473,785 Members | 2,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="ale rt(id)" //parent div
Div4 bla bla bla bla on div 4
<div id="myembeddedd iv"ondblclick=" alert(id)" // child div
Div4.1 bla bla bla on embedded Div
</div>
</div>

When I double click within the embedded div (id=myembeddedd iv) 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 2780
Num GG meinte:
Hi all,

Given this simple code:

<div id="mydiv" ondblclick="ale rt(id)" //parent div
Div4 bla bla bla bla on div 4
<div id="myembeddedd iv"ondblclick=" alert(id)" // child div
Div4.1 bla bla bla on embedded Div
</div>
</div>

When I double click within the embedded div (id=myembeddedd iv) 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...@gregork ofler.atwrote:
Num GG meinte:
Hi all,
Given this simple code:
<div id="mydiv" ondblclick="ale rt(id)"* * * * * * ** * //parent div
Div4 bla bla bla bla on div 4
* <div id="myembeddedd iv"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
3886
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 150px. The center cell has no specific width and therefore grows/shrinks as the browser window is re-sized. In the center cell is a <div>, set to display with the properties set
4
5241
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 from a text file. The last value is variable length- the shortest return is about 300 characters, and the longest is about 6000 or so. This SSI lives inside a <div> on a page with a few other text <div>s; a simplified example of the layout is: ...
1
7056
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
13158
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 this, with a flush left margin:
6
1502
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. SHOULD BE Microsoft introduced a shortcut that can be used to reference elements THAT ARE NOT FORM CONTROLS WITHIN A FORM ELEMENT which include an ID attribute where the ID becomes A PROPERTY OF THE GLOBAL WINDOW OBJECT and the scope of the window...
21
4454
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 number is clicked, I want the DIV to show up for that week next to it, like I have in the following example: http://www.bowlingballsandmore.com/bsa/EditScores.gif Can anyone point me in the right direction or give me an example?
6
4666
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 now I hope to recode it using CSS to make it easier to update. Anyway, I'm starting to get my own tales of whoa with CSS and IE, and I need the assistance of the group to see if anyone has options on how to resolve this. The site is actually...
1
3486
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 the sidebar (right) doesn't center here's the css i'm modifying to center it. i apologise for the mess. <html> <head> <title>cris-kun's 'Blog - www.puff-x.com</title> <$BlogMetaData$>
1
2581
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. .splash { z-index: 2; width: 135px; height: 386px; margin: 0 auto; position: relative; left: 450px;
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.