jQuery filter not() and filter() example code_jquery
$ (function(){
$("li").not(":even").css("color","red");
$("li").filter(":odd" ).css("color","red");
})
The second way of writing:
$(function(){
$("li").filter(function(index ) {
return index%2 == 0;
}).css("color","red");
$("li").not(function(index) {
return index%2 !== 0;
}).css("color","red");
})
Both of these writing methods can be used To achieve the same effect, not and filter are opposite filters!
jQuery filter selector:not() method introduction
jQuery(':not(selector)')
In earlier versions of jQuery, the :not() filter only supports A simple selector means that the selector we pass into the :not filter can be arbitrarily complex, such as: not(div a) and :not(div,a)
"a" >sdfsdfs
"b">sdfsdfs
"c">sdfsdfs
$ ("p:not(.a)").css({"color":"red"})
Then except for the p element whose class is equal to a, the text color of other P will become red.
:not() pseudo-class filter selector. This name is really hard to pronounce. jQuery’s :not() method is jQuery’s pseudo-class selector. It can filter out unnecessary elements and filter out the correct results. Simply put, we There is the following code:
$("selector1:not(selector2)")
Let’s analyze the above code. We want to get the elements of selector1, but maybe I don’t need them all. What should I do? Pass: not() method to filter, if there are #1, #2, #3, #4 in selector1's collection
Our selector2 is to filter out #4. With the above code, we will eventually get #1, #2, #3
A few more examples
$('li:not(:only-child)')//Match all li except
$('li which has only one child element :not(:first-child)');//Match LI
$("li :not(:first)").hide();// Hide all LI except the first LI

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
![How to solve the '[Vue warn]: Failed to resolve filter' error](https://img.php.cn/upload/article/000/887/227/169243040583797.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
Methods to solve the "[Vuewarn]:Failedtoresolvefilter" error During the development process using Vue, we sometimes encounter an error message: "[Vuewarn]:Failedtoresolvefilter". This error message usually occurs when we use an undefined filter in the template. This article explains how to resolve this error and gives corresponding code examples. When we are in Vue

1. Filter First look at the location of the filter of the web server. Filter is a chain connected before and after. After the previous processing is completed, it is passed to the next filter for processing. 1.1Filter interface definition publicinterfaceFilter{//Initialization method, only executed once in the entire life cycle. //Filtering services cannot be provided until the init method is successfully executed (failure such as throwing an exception, etc.). //The parameter FilterConfig is used to obtain the initialization parameter publicvoidinit(FilterConfigfilterConfig)throwsServletException;//

Detailed explanation of CSS fuzzy attributes: filter and background-filter Introduction: When designing web pages, we often need some special effects to increase the visual appeal of the page. The blur effect is one of the common special effects. CSS provides two blur attributes: filter and background-filter, which are used to blur element content and background content respectively. This article explains these two properties in detail and provides some concrete code examples. 1. filter

Note 1. If the Lambda parameter generates a true value, the filter (Lambda that can generate a boolean result) will generate an element; 2. When false is generated, this element will no longer be used. Example to create a List collection: ListstringCollection=newArrayList();stringCollection.add("ddd2");stringCollection.add("aaa2");stringCollection.add("bbb1");stringC

Analysis of CSS visual properties: box-shadow, text-shadow and filter Introduction: In web design and development, CSS can be used to add various visual effects to elements. This article will focus on the three important properties of box-shadow, text-shadow and filter in CSS, including their usage and effect display. Below we analyze these three properties in detail. 1. box-shadow (box shadow) box-shado

Optional class in Java8: How to use the filter() method to filter possibly null values In Java8, the Optional class is a very useful tool that allows us to better handle possibly null values and avoid the occurrence of NullPointerException. The Optional class provides many methods to manipulate potential null values, one of the important methods is filter(). The function of the filter() method is that if Option

Use filters to format and process data in Vue In Vue, we can format and process data by using filters. Filter is a function that can be called directly in the template. It can process the data to be displayed and return the processed results. In this article, we will introduce how to use filters to format and process data, and provide specific code examples. Register filter In the Vue instance, we need to register a filter first so that it can be used in the model

First define a Filter for unified access URL interception. The code is as follows: publicclassUrlFilterimplementsFilter{privateLoggerlog=LoggerFactory.getLogger(UrlFilter.class);@OverridepublicvoiddoFilter(ServletRequestrequest,ServletResponseresponse,FilterChainchain)throwsIOException,ServletException{H
