I have the following HTML:
<div class="server" id="32">
<a>Server Name</a>
<div class="delete-server">X</div>
</div>
I am trying to make it so when users click the server
div it brings up an edit dialog. The problem is simply doing:
$(".server").click(function () {
//Show edit dialog
});
Does not work, because if they click the X which is delete, it brings up the edit dialog. How can make the entire div server
have the click event except the delete-server
div.
There is an alternative way to solve this:
Just make sure a click event issued on
.delete-server
does not bubble up to the parent element.Just check what is the element who triggered the event:
LIVE DEMO
Only this works for me.
js_object
is jQuery object for meta parent like a$('body')
Fore your case:
server — js-parent
delete-server — js-child-1
Here's the fiddle: http://jsfiddle.net/9bzmz/3/