Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Processing HTML events in Javascript - problem
Old 06-24-2007, 01:32 PM Processing HTML events in Javascript - problem
Junior Talker

Posts: 4
Trades: 0
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?
medvegonok is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-24-2007, 03:03 PM Re: Processing HTML events in Javascript - problem
Extreme Talker

Posts: 238
Location: United States
Trades: 0
Quote:
Originally Posted by medvegonok View Post
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.
frost is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Processing HTML events in Javascript - problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.72231 seconds with 12 queries