Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-15-2012, 01:45 PM   PM User | #1
arnocazino
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
arnocazino is an unknown quantity at this point
help needed for clickhandler function

The clickHandler function was supposed to display the name of the node or element on which the user clicked. By attaching the function to the body element the whole page was "clickable".


function clickHandler(e) {
var obj = e.XXXXX;
alert(obj.XXXXX);
return false;
}
<body onload="return XXXXXXX (event);">

Can you please tell me what replaces the XXXXXX?

thx guys im strugglin a bit
arnocazino is offline   Reply With Quote
Old 11-15-2012, 08:50 PM   PM User | #2
minder
Banned

 
Join Date: Oct 2012
Posts: 81
Thanks: 0
Thanked 4 Times in 4 Posts
minder can only hope to improve
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <title></title>
        <script type="text/javascript">
            function whichElement(e){
                var targ;
                if (!e){
                    var e=window.event;
                }
                if (e.target){
                    targ=e.target;
                }else if (e.srcElement){
                    targ=e.srcElement;
                }
                if (targ.nodeType==3) { // defeat Safari bug
                    targ = targ.parentNode;
                }
                var tname;
                tname=targ.tagName;
                alert("You clicked on a " + tname + " element.");
            }
        </script>
    </head>
    <body onmousedown="whichElement(event)">
        <p>Click somewhere in the document. An alert box will alert the tag name of the element you clicked on.</p>

        <h3>This is a header</h3>
        <p>This is a paragraph</p>
        <img src="ball.gif"  alt="Ball" />
    </body>
</html>
Modify to suit.

Last edited by minder; 11-15-2012 at 08:54 PM..
minder is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 09:16 AM.


Advertisement
Log in to turn off these ads.