[thelist] javascript newbie need a hand

Joshua Olson joshua at waetech.com
Tue May 28 08:08:01 CDT 2002


----- Original Message -----
From: "[Gauthier at PlacidSound]" <gauthier at placidsound.com>
Sent: Tuesday, May 28, 2002 6:26 AM


> so two questions:
>     -how can I set the elm.onclick property (should I call it a
property???) to call the oposite function?
>     -how can I avoid onclick event of parents elements (try clicking on a
submenu item)

Hey there,

You can avoid clicking the parent by adding a few items:

add this to both functions - event.cancelBubble = true;
add this to the each onclick event handler as the last command - return
false;

That should do what you need.  The DOM passes the events to the parent
element by default.  The first item, event.cancelBubble = true, disables
this behavior.  The "return false" also tells the browser that the onclick
failed and therefore should not take any action.  This is normally
associated with anchor tags, where returning false will tell the page not to
change to the value of the href attribute.  However, it is probably a good
idea to get into the habit of returning true or false on every event
handler.

-joshua





More information about the thelist mailing list