Home > Web Front-end > JS Tutorial > body text

jQuery filter selector: introduction to using the not() method_jquery

WBOY
Release: 2016-05-16 16:51:56
Original
1530 people have browsed it

jQuery(':not(selector)')

In early versions of jQuery, the :not() filter only supports simple selectors, which means that the selector we pass into the :not filter can be arbitrary. Complex, such as: not(div a) and :not(div,a)

Copy code The code is as follows:

"a">sdfsdfs


"b">sdfsdfs


"c"> ;sdfsdfs


$("p:not(.a)").css({"color":"red"})

Then except that class is equal to p Outside the element, the text color of other P becomes red.

:not() pseudo-class filter selector. This name is really hard to pronounce. jQuery’s :not() method is jQuery’s pseudo-class selection The filter can filter out unnecessary elements and filter out the correct results. Simply put, we have the following code:
Copy code Code As follows:

$("selector1:not(selector2)")

Let’s analyze the above code. We want to get the elements of selector1, but maybe I don’t need it. All, what to do, filter through the :not() method, if there are #1, #2, #3, #4 in the selector1 collection

Our selector2 is to filter out #4, the above code We will end up with #1, #2, #3

Just a few more examples
Copy code Code As follows:

$('li:not(:only-child)')//Match all li, except
$('li:not(:first) which has only one child element -child)');//Match except LI which is the first child element in its parent element
$("li :not(:first)").hide();//Hide except the first one All LI except LI
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template