471,854 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,854 software developers and data experts.

Embedded <divs> with events: How to prevent the parent div's eventfrom being fired when the embedded div's event is fired?

Hi all,

Given this simple code:

<div id="mydiv" ondblclick="alert(id)" //parent div
Div4 bla bla bla bla on div 4
<div id="myembeddeddiv"ondblclick="alert(id)" // child div
Div4.1 bla bla bla on embedded Div
</div>
</div>

When I double click within the embedded div (id=myembeddeddiv) the
corresponding alert occurs: a javascript Alert "myembeddeddiv". This
is normal.

But, as i clicked on the embedded div, the parent div thinks he's been
clicked too, so the corresponding alert occurs: a javascript Alert
"mydiv". This is pretty normal too as the child div is embedded in the
parent div. Normal... but not wanted in my case.

So, the question is: In case of embedded divs which have the same
event, is there a _simple_ way to prevent the parent div's event from
being fired when the embedded div's event is fired?

Thanks to all.

Num

Nov 10 '08 #1
2 2677
Num GG meinte:
Hi all,

Given this simple code:

<div id="mydiv" ondblclick="alert(id)" //parent div
Div4 bla bla bla bla on div 4
<div id="myembeddeddiv"ondblclick="alert(id)" // child div
Div4.1 bla bla bla on embedded Div
</div>
</div>

When I double click within the embedded div (id=myembeddeddiv) the
corresponding alert occurs: a javascript Alert "myembeddeddiv". This
is normal.
A.k.a. as event bubbling.
But, as i clicked on the embedded div, the parent div thinks he's been
clicked too, so the corresponding alert occurs: a javascript Alert
"mydiv". This is pretty normal too as the child div is embedded in the
parent div. Normal... but not wanted in my case.

So, the question is: In case of embedded divs which have the same
event, is there a _simple_ way to prevent the parent div's event from
being fired when the embedded div's event is fired?
http://www.quirksmode.org/js/events_order.html

scroll down to "turning it off".

Gregor
Nov 10 '08 #2
On 10 nov, 16:26, Gregor Kofler <use...@gregorkofler.atwrote:
Num GG meinte:
Hi all,
Given this simple code:
<div id="mydiv" ondblclick="alert(id)"* * * * * * ** * //parent div
Div4 bla bla bla bla on div 4
* <div id="myembeddeddiv"ondblclick="alert(id)"* *// child div
* Div4.1 bla bla bla on embedded Div
* </div>
</div>
[...]
>
http://www.quirksmode.org/js/events_order.html

scroll down to "turning it off".

Gregor
Thanks Gregor for this link. It's very well explain.

I got it

Cheers.

Num
Nov 17 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mark Bennett | last post: by
1 post views Thread by Karl | last post: by
6 posts views Thread by =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.