Well, you should explicitly declare your variables. Events assigned in this manner need to have themselves formally declared as functions. And, javascript onclick is all lower case:
Code:
<script language="text/javascript">
window.onload=function() {
var anc=document.getElementsByTagName('a');
for(var c=0;c<anc.length;c++) {
if(anc[c].className=='artist'){
anc[c].onclick=function(){this.style.backgroundImage='url(image/main03/ArrowDown.gif)';};
}
}
}
</script>
Declaring variables helps to prevent conflicts with other code. Using the correct case for events is essential, otherwise they will not get executed, as is using the formal function assignment when assigning an event this way.
Now, javascript usually succeeds in altering css styles. Always, in fact, if the javascript styles are instituted after the css styles are parsed and if the javascript styles carry equal or greater weight than the css styles.
Without seeing your page, I would have to guess (if you are still having problems) that since you are using the onclick event, the link is firing before you can see any result anyway. Changes made by javascript will not persist across pages or on reload of a page, unless preserved in and retrieved from cookies.
Another thing to keep in mind is that if you are using the onclick event and you don't want the link to fire, the event must return false:
Code:
function(){this.style.backgroundImage='url(image/main03/ArrowDown.gif)';return false;}
Bookmarks