472,965 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,965 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 2746
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark Bennett | last post by:
Hello, Embarrassing as it is, I'm stumped by a (I'd imagine) fairly elementary CSS problem. Consider the code below. We have a table with three columns, two of which are set to a width of...
4
by: smiley | last post by:
I hope this is the right forum for this question; i know it crosses over a few topics but here goes. I have a page that uses a server-side include perl script to return a list of name/value pairs...
1
by: Karl | last post by:
given: <div id="header"> <div id="tdate"> <div id="photo"> </div> </div> </div> The two embedded divs insist on arranging themselves one on top of the
3
by: TR | last post by:
Is it possible with CSS to prevent this wrapping alignment with a checkbox with a nested label? This is the label of the checkbox that wraps beneath it I'd prefer it looked like...
6
by: =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= | last post by:
At <http://jibbering.com/faq/index.html#FAQ4_41> IS Microsoft introduced a shortcut that can be used to reference elements which include an ID attribute where the ID becomes a global variable....
21
by: BLarche | last post by:
I am not really sure how to do this, but I need to create <DIV>'s that correspond to a given week that is clicked. So, when my ASP is generating the page, it will create the hidden divs. When a week...
6
by: Alex | last post by:
Hi Everyone, I'm not completely new to CSS, but I've never written an entire site in CSS, which is what I'm doing now. I wrote our website many years ago using tables to format the page, but...
1
by: judacris | last post by:
I've seen the threads here about molding 2 divs in a centered fashion. but I can't seem to solve this thing. my blogger blog is functioning well on my site for now, but the blog feed (left) and...
1
by: Daimz | last post by:
I am making a blog and as part of my template I am wanting to have my header and then another image on the side of that using the z-index: 2; to make it that layer about. so here is the css. ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...

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.