JQuerys :not() selector is used to filter in some cases when we have some selectors. It selects all the elements except the elements that matches the selector.
for example, If we have some checkboxes. When we select any checkbox the background color will be changed. To apply this we simply add this line $('input[type=checkbox]') to select that checkbox and add the click event on it. But that will also selects other checkboxes.
Example:
$('input[type=checkbox]').click(function() {
if(this.checked == true) {
$(this).parent().parent().addClass('active');
} else {
$(this).parent().parent().removeClass('active');
}
});
If we want to apply the css to all the checkbox except the checkbox with id noselect then we can write it as follows:
Example:
$('input[type=checkbox]:not("#noselect")').click(function() {
if(this.checked == true) {
$(this).parent().parent().addClass('active');
} else {
$(this).parent().parent().removeClass('active');
}
});
0 Comment(s)