WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

jQuery Traversing - Filtering


Narrow Down The Search For Elements

The three most fundamental sifting strategies are first(), last() and eq(), which enable you to choose a particular component dependent on its situation in a gathering of components.

Other separating strategies, similar to channel() and not() enable you to choose components that coordinate, or don't coordinate, a specific criteria.


jQuery first() Method

The first() technique restores the primary component of the chose elements.

The following precedent chooses the first <p> component inside the first <div> element:

Example

$(document).ready(function(){
    $("div p").first();
});
Try it yourself »

jQuery last() Method

The last() technique restores the last component of the chose elements.

The following model chooses the last <p> component inside the last <div> element:

Example

$(document).ready(function(){
    $("div p").last();
});
Try it yourself »

jQuery eq() method

The eq() technique restores a component with a particular list number of the chosen elements.

The list numbers begin at 0, so the principal component will have the file number 0 and not 1. The accompanying precedent chooses the second <p> component (record number 1):

Example

$(document).ready(function(){
    $("p").eq(1);
});
Try it yourself »

jQuery channel() Method

The channel() strategy gives you a chance to determine a criteria. Components that don't coordinate the criteria are expelled from the choice, and those that match will be returned.

The following precedent returns all <p> components with class name "intro":

Example

$(document).ready(function(){
    $("p").filter(".intro");
});
Try it yourself »

jQuery not() Method

The not() strategy restores all components that don't coordinate the criteria.

Tip: The not() strategy is the inverse of filter().

The following precedent returns all <p> components that don't have class name "intro":

Example

$(document).ready(function(){
    $("p").not(".intro");
});
Try it yourself »

jQuery Traversing Reference

For a total review of all jQuery Traversing strategies, it would be ideal if you go to our jQuery Traversing Reference.