0

Here I have two click events:

$(document).ready(function() {

    //MESSAGES CHECKBOX
    $(document).on("click",".messages_checkbox",function () {
        alert("clicked box");
    });

    //MESSAGES ROW
    $(document).on("click",".messages_row",function () {
        alert("clicked");
    });

});

And here is the html:

<tr class="messages_row">";
<td><input type="checkbox" class="messages_checkbox" value="1"></td>
</tr>

As you can see, one object is inside another. What I would like to do is fire mutually exclusive (either one or the other - never both) events when either the check box is clicked, or the container itself is clicked.

Right now both events fire if I click the checkbox, one after the other. I only want the checkbox event to fire.

How would I do this?

Amy Neville
  • 10,067
  • 13
  • 58
  • 94

1 Answers1

1
$(document).on("click",".messages_checkbox",function () {
    alert("clicked box");

    // Stops the bubbling
    return false;
});

//MESSAGES ROW
$(document).on("click",".messages_row",function () {
    alert("clicked");

    // Stops the bubbling        
    return false;
});

Make sure to read this answer

Community
  • 1
  • 1
gdoron
  • 147,333
  • 58
  • 291
  • 367