Latest web development tutorials

jQuery traversal - Filter

The scope of the search elements Acronym

Three basic filtering methods are: first (), last () and eq (), which allows you to based on its location in a group element to select a specific element.

Other filtering methods, such as filter () and not () allows you to select a particular match or do not match the specified criteria elements.


jQuery first () method

first () method returns the first element of the selected element.

The following examples select the first <div> element inside the first <p> element:

Examples

$(document).ready(function(){
$("div p").first();
});

try it"


jQuery last () method

last () method returns the last element of the selected element.

The following example selects the last <div> element in the last <p> element:

Examples

$(document).ready(function(){
$("div p").last();
});

try it"


jQuery eq () method

eq () method returns the selected element is the element with the specified index number.

Index numbers start at 0, so the index of the first element is 0 instead of 1. The following examples select the second <p> element (index number 1):

Examples

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

try it"


jQuery filter () method

filter () method allows you to specify a standard. This standard does not match the element will be removed from the collection, matching element will be returned.

The following example returns all <p> element with the class name "url" of:

Examples

$(document).ready(function(){
$("p").filter(".url");
});

try it"


jQuery not () method

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

Tip: not () method filter () instead.

The following example returns all <p> elements without a class name "url" of:

Examples

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

try it"