469,315 Members | 1,572 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

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 2614
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.