Javascript nested elements events

Posted on 2007-08-09
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

    I was thinking about

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

    but I think you need the opposite :)
    LVL 4

    Assisted Solution

    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


    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 =;


    Featured Post

    Course: HTML5 Specialist

    HTML5 development skills are critical to all developers. HTML5 is the foundation to almost any development process. That's why business, design studios, development shops and other organizations need HTML5 developers. Get your foot in the door as a HTML5 specialist.

    Join & Write a Comment

    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    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…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now