• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 767
  • Last Modified:

Javascript nested elements events

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.
0
percyhoff
Asked:
percyhoff
2 Solutions
 
Michel PlungjanIT ExpertCommented:
I was thinking about

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

but I think you need the opposite :)
0
 
jr001Commented:
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).
0
 
percyhoffAuthor Commented:
Hello,

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;

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now