Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is the use of jQuery filter?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 371
    Comment on it

    Hello Readers,

    Jquery filter is one of the jquery method. It is used to returns the elements that match the certain values from the object list.

    Syntax :

    selector.filter( selector )
    

    Parameters :

    selector

    Below is the Code Example of filter() method :

    <html>
        <head>
          <title>The jQuery Example</title>
          <script type = "text/javascript" 
             src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    
          <script type = "text/javascript" language = "javascript">
             $(document).ready(function() {
                $("li").filter(".middle").addClass("selected");
             });
          </script>
    
          <style>
             .selected { color:red; }
          </style>
       </head>
    
       <body>
    
          <div>
             <ul>
                <li class = "top">list item 1</li>
                <li class = "top">list item 2</li>
                <li class = "middle">list item 3</li>
                <li class = "middle">list item 4</li>
                <li class = "bottom">list item 5</li>
                <li class = "bottom">list item 6</li>
             </ul>
          </div>
    
       </body>
    
    </html>
    

    Output :

    list item 1
    list item 2
    list item 3
    list item 4
    list item 5
    list item 6
    

    In the above code, we filter the class (.middle) and addClass (selected) on it.

 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: