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

N

Num GG

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
 
G

Gregor Kofler

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
 
N

Num GG

Num GG meinte:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top