[thelist] Trapping JS events

Jeff Howden jeff at jeffhowden.com
Thu Jul 3 03:24:00 CDT 2003


> From: Chris Evans
> I have a div that contains a form element. Both have
> onMouseDown handlers.  When I click on the form element,
> both handlers get fired, first the form element handler,
> then the containing DIV handler.
> [snip]
> When I click on the input box, I get an alert for First
> Event, then one for Second Event.   Is there a way I
> can have the form element event handler trap the mouse
> click so that the containing DIV event handler doesn't
> get called?

i've had some luck with the following:

function cancelEvent()
    return false;
    window.event.cancelBubble = true;

 onmousedown="alert('Second Event')">
   onmousedown="alert('First Event'); return cancelEvent()">

good luck,


Jeff Howden - Web Application Specialist
Resume - http://jeffhowden.com/about/resume/
Code Library - http://evolt.jeffhowden.com/jeff/code/

More information about the thelist mailing list