I have the following html markup on my page,
<div id="sig_container">
<div id="layer1" class="layer ui-draggable ui-resizable ui-resizable-autohide">
<div id="layer2" class="layer ui-draggable ui-resizable ui-resizable-autohide">
<div id="layer3" class="layer ui-draggable ui-resizable selected ui-resizable-autohide">
</div>
On this page I am trying to select the #sig_container div without selecting any of the children. However I am having an issue doing so. The selector either selects everything or nothing.
Thanks in advance
Daniel
Edit: Sorry i should add I am trying to add a click event on the container. So i want the event to fire only when i click the container and not the children.
You can accomplish what you want by testing the
event.targetof the click event.The reason for this is that click events naturally bubble, so if you click one of the children, the event bubbles up to the
sig_containerand fires its handler.With this solution, you make sure that the
targetof the event was actually thesig_containerbefore it fires the code.So basically:
thisis thesig_containerevent.targetis the actual element clickedif
thisis the same as theevent.targetrun the code