1

In the following code, how can I make it so clicking the checkbox or input field doesn't toggle the row selection? I tried using the not() selector as in:

$('#example tbody').on('click', 'tr:not(input)', function () ...

http://jsfiddle.net/kevmor/7txDz/

2
  • Thanks that works but now I realized I have another problem, I'm using a checkbox per row as a 'select all' checkboxes for the row. If I stop the bubble up is there a way I can still do the select all (checkboxes)? Commented May 12, 2014 at 21:33
  • The selector 'tr:not(input)' selects all <tr> elements which are also not <input> elements. Really, the only way to "select a tr excluding specific descendants" is to do the stopPropagation approach @DylanHayes shows below, I believe. I wanted to do exactly what you're describing, and this worked for me. Commented Dec 5, 2018 at 18:08

2 Answers 2

1

This is called Event Bubbling.

jQuery stopPropagation bubble down

Use:

$('input').on('click', function (e) {
   e.stopPropagation();
})
Sign up to request clarification or add additional context in comments.

Comments

0

use e.stopPropagation() on inputs:

$('#example tbody').on('click', ':input', function(e){
   e.stopPropagation(); // stops the event to bubble up to the dom tree
}).on('click', 'tr', function () ...

Demo


:input in jQuery selects all the form elements including checkboxes, radios, textareas, selects etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.