Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jQuery :not() selector

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 215
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: