Quote:
Originally Posted by medvegonok
In the following code I am trying to print out the value of document.body.onclick from javascript:
<BODY onclick="alert('ok')">
...
<script type="text/javascript">
alert(document.body.onclick);
</script>
...
</BODY>
However, the alert in Javascript code prints out "undefined" when I open this page and not the actual value of onclick. Could somebody help me?
|
There are two ways to get the value of an element attribute. Unfortunately, neither of them fully work in IE.
alert(document.body.getAttribute('onload'));
This will display alert('ok') in Firefox, Opera, and Safari, and function anonymous{ alert('ok') } in IE.
alert(document.body.attributes['onload'].value)
This will display alert('ok') in Firefox, Opera, and Safari, and null in IE.
|