Forum Moderators: open
If there always is only one element returned, you can use document.getElementsByTagName("td")[0].onclick, but you would probably want to loop over the elements, like this:
tds = document.getElementsByTagName("td");
for( var x=0; x < tds.length; x++ ) {
tds[x].onclick = function(){
alert('Click!');
};
}
For testing, I changed the script from td to h3, as there is only one of those and set the script to:
<script type="text/javascript">
document.getElementsByTagName("h3")[0].onclick=function(){alert("click");}
</script>
Unfortunatly, this doesn't seem to work either.
Do I need to "turn on" this thing or will JavaScript always be watching out for the onclicks, or do I need to put it in something like onload?
Thanks