Home >Web Front-end >JS Tutorial >How to use jQuery filter function_jquery

How to use jQuery filter function_jquery

WBOY
WBOYOriginal
2016-05-16 16:47:391502browse

Use the filter function to filter qualified DOM elements from the wrapper set.

If we have an html file with the following content, we can easily get the element with class external by using filter.

Copy code The code is as follows:

link
link
link
link
link
< a href="#">
link
link
link
link

The parameter types of filter can be divided into There are two types:

1 Pass the selector

2 Pass the filter function

If you use the selector as a parameter, the usage is as follows
Copy code The code is as follows:

$('a').filter('.external')

Use the anonymous filter function
Copy the code The code is as follows:

$('a').filter (function(index) {
return $(this).hasClass('external');
})

The parameter index is the subscript of the result set.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn