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

Discussion in 'Javascript' started by Num GG, Nov 10, 2008.

  1. Num GG

    Num GG Guest

    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
     
    Num GG, Nov 10, 2008
    #1
    1. Advertising

  2. Re: Embedded <divs> with events: How to prevent the parent div'sevent from being fired when the embedded div's event is fired?

    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
     
    Gregor Kofler, Nov 10, 2008
    #2
    1. Advertising

  3. Num GG

    Num GG Guest

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

    On 10 nov, 16:26, Gregor Kofler <> wrote:
    > 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
     
    Num GG, Nov 17, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VG9ueSBKb2hu?=

    Events being fired multiple number of times...

    =?Utf-8?B?VG9ueSBKb2hu?=, Dec 11, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    375
    =?Utf-8?B?VG9ueSBKb2hu?=
    Dec 11, 2004
  2. Christofer Dutz
    Replies:
    1
    Views:
    1,012
    Neredbojias
    Aug 29, 2005
  3. Pete C
    Replies:
    6
    Views:
    818
    Ron Natalie
    Oct 30, 2005
  4. Iams

    Events aren't being fired

    Iams, Mar 17, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    126
  5. .rhavin grobert

    dynamic/javascript: div in div = 3 divs..!?

    .rhavin grobert, Nov 20, 2009, in forum: Javascript
    Replies:
    11
    Views:
    219
    Thomas 'PointedEars' Lahn
    Nov 20, 2009
Loading...

Share This Page