I need a selector that says:
Any table cell that has a checkbox in it
Right now, I’m using:
$('td input').filter(':checkbox').each(function() {
$(this).closest('td').addClass('CursorPointer');
});
$('td.CursorPointer').on('click',function() {
$('input:checkbox',this).click();
});
It works, but it might not be “best”.
Use the
:has()selector or thehas()method:Note that
input:checkboxis equivalent toinput[type="checkbox"]in Sizzle/jQuery.Your code sample could be rewritten as:
Or…
Note that
.has()is more efficient than:has: http://jsperf.com/jquery-has-vs-has Although:has()is slightly more readable IMHO.