By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,101 Members | 1,463 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,101 IT Pros & 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?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.