[Last Call] Learn how to a build a cloud-first strategyRegister Now


Javascript nested elements events

Posted on 2007-08-09
Medium Priority
Last Modified: 2010-08-05
Hello all,

I have a <div> tag with a table nested in it. I want to perform a drag and drop funtion on the <div> based upon the div id property. The problem I am having is that when I use the event.getElementById and click inside the table nested in the div the ID property is an empty string because the table cell fires the event rather than the div tag. Any help will be greatly appreciated.
Question by:percyhoff
LVL 75

Accepted Solution

Michel Plungjan earned 750 total points
ID: 19668002
I was thinking about

    if (event.stopPropagation) event.stopPropagation();
    else event.cancelBubble = true;

but I think you need the opposite :)

Assisted Solution

jr001 earned 750 total points
ID: 19668461
Every event is triggered in inner-most element 1st, and then it is propagated outwards, unless it gets canceled of course. This is how things work.

If you wish for an event never to reach the table in question, then you must create an overlay (layer) over it and catch the event there.

So you have two options now, either let the event to propagate to the div or create transparent div exactly over the table and catch this event there and cancel its propagation (see above).

Author Comment

ID: 19669848

Thanks for the prompt reply. What do I need to do to let the event bubble to the parent element? Rather than being handled by the child. This is what I have right now that is returning the child element ID:  

objectID = event.srcElement.id;


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question