Loading Please Wait...

Logo Lynxsia IT Solutions

jQuery Traversing - Filtering

JQ DOM Traversing - Filtering

jQuery provides filtering methods, which allow you to select a specific element based on its position in a group of elements.

Filtering HTML DOM

The most basic filtering methods are first(), last() and eq(), which allow you to select a specific element based on its position in a group of elements.

Other filtering methods, like filter() and not() allow you to select elements that match, or do not match, a certain criteria.

  • first()
  • last()
  • eq()
  • filter()
  • not()
jQuery first() Method

The jQuery first() method returns the first element of the specified elements.

The following example selects the first <div> element:

					 
        
          $(document).ready(function(){
            $("div").first();
          });
        
      
jQuery last() Method

The jQuery last() method returns the last element of the specified elements.

The following example selects the last <div> element:

					 
        
          $(document).ready(function(){
            $("div").last();
          });
        
      
jQuery eq() Method

The jQuery eq() method returns an element with a specific index number of the selected elements.

The index numbers start at 0, so the first element will have the index number 0 and not 1. The following example selects the second <p> element (index number 1):

					 
        
          $(document).ready(function(){
            $("p").eq(1);
          });
        
      
jQuery filter() Method

The jQuery filter() method lets you specify a criteria. Elements that do not match the criteria are removed from the selection, and those that match will be returned.

The following example returns all <p> elements with class name "intro":

					 
        
          $(document).ready(function(){
            $("p").filter(".intro");
          });
        
      
jQuery not() Method

The jQuery not() method returns all elements that do not match the criteria.

The not() method is the opposite of filter().

The following example returns all <p> elements that do not have class name "intro":

					 
        
          $(document).ready(function(){
            $("p").not(".intro");
          });
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved