Justin Justin - 1 year ago 111
Javascript Question

jQuery Click Event On Div, Except Child Div

I have the following HTML:

<div class="server" id="32">
<a>Server Name</a>
<div class="delete-server">X</div>

I am trying to make it so when users click the
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
have the click event except the

Answer Source
$(".server").on('click', ':not(.delete-server)', function (e) {
     // Show edit dialog

Here's the fiddle: http://jsfiddle.net/9bzmz/3/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download