The has (selector selector or DOM element) sets the matching element collection to the condition of the selector or DOM element, retrieves whether the condition exists in the descendants of each element, and makes the qualifying element a new result set.Here's an example:$ (' Li '). has (' span '). CSS (' background-color ', ' red ');the results are as follows:This example shows that when you match Li, you check that the descendant elements of the li contain a span, and if so, the element is inc
();//All sibling Nodes$("#test1"). Siblings ("#test2"); $("#test"). Find ("#test1");Three, Element filter//The following methods return a new jquery object that contains the filtered elements$("ul Li"). EQ (1);//Select an element in UL Li that matches the index order of 1 (that is, the 2nd Li Element)$("ul Li"). First ();//Select the first element to match in ul Li$("ul Li"). Last ();//Select the last elem
Copy codeThe Code is as follows:Content Filtering selector: gets an element based on the text content in the element or its child element features. The text content can be fuzzy or absolutely matched for element locating.JQuery selector detailsBased on the elements in the obtained page, jQuery selectors can be divided into four categories: Basic selector, level selector, filter selector, and form selector.
InstanceChange the color of all div, and then add a border to the class named "Middle":$ ("div"). CSS ("Background", "#c8ebcc") .filter(".middle") . CSS ("Border-color", "Red");Definition and usageThe filter () method reduces the set of matching elements to the element that matches the specified selector.Grammar. Filter (selector)Using
Find () searches for elements whose class is classname In the div element.Filter () is used to filter the elements whose class is classname.It is basically the find sub-element query, and the filter is the level query.· The find function is used to query the child element of the current object set;· The filter function filters the current object set and uses
Has (selector or DOM element) matches the Element Set Based on the selector or DOM element as the condition to retrieve whether the condition exists in the descendant of each element, create a new result set with the matching elements.
The following is an example:
Copy codeThe Code is as follows: Copy codeThe Code is as follows: ('li'hangzhou.has('span'hangzhou.css ('background-color', 'red ');
The result is as follows:
In this example, we can see that, when matching li, we need to check whethe
JQuery (': Not (selector) ')
In earlier versions of jquery, the not () filter only supported a simple selector, stating that we passed in: not the selector in this filter can be arbitrarily complex, for example: not (div a) and:not (div,a)
Copy Code code as follows:
$ ("P:not (. a)"). CSS ({"Color": "R
1, find () method, the difference between children methods:First look at the English explanation bar:Children method:Find Method:
First look at the English explanation bar:Through the above explanation, can be summarized as follows:Both 1:children and find methods are used to obtain the element's child elements, neither of which returns text node, as most jquery methods do.The 2:children method obtains only the element one subordinate child element, n
1. Match elements According to a filter rule, which begins with the ":" sign, and is typically used to find a single element of a position in a collection element.$ ("Li:first") the first one$ ("Li:last") Last2. If you want to flexibly select any one of the tag elements from a set of tag element arrays, we can use: EQ (index)Where the parameter index represents the index number (that is, an integer), which starts at 0.If the value of index is 3, it me
Copy Code code as follows:
Content Filter Selector: Gets the element based on the text content in the element or the contained child element feature, and the text content can be positioned in a fuzzy or absolute match
jquery Selector Detailed
Depending on the elements in the obtained page, you can divide the jquery selector into: basic selector, hierarchy
The Visibility filter selector selects the appropriate element based on the visible and invisible state of the element.Show hidden Examples:DOCTYPE HTML>HTML>Head>Scriptsrc= "/jquery/jquery-1.11.1.min.js">Script>Scripttype= "Text/javascript">$ (document). Ready (function(){ $("#hide"). Click (function(){ $("P"). Hide (); }); $("#show"). Click (function(){ $("
Usage of attribute filter selector in JQuery
This document describes how to use the attribute filter selector in JQuery. Share it with you for your reference. The details are as follows:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 4
, function (elementOfArray, indexInArray) [, invert])$. The grep () function removes unnecessary elements and acts as a filter. By passing its elements through a test function, that is, the second parameter of grep, note that the parameters here are in the opposite order of the callback functions of the previous two functions. These two parameters are used to control which elements you need and return them through the return Statement (return true ind
I have never been very clear about the differences between the filter () method and the find () method. Today I am looking at the jQuery Cookbook book and finally I have figured it out.Filter () filters DOM element packaging sets. It is used to operate the current Element Set and delete unmatched elements to obtain a new set.Copy codeThe Code is as follows:$ ('Div '). f
This is the 2 common methods used in jquery.Their 2 functions are completely different, while beginners tend to be misled.First we look at the. Find () Method:Now there is a page with HTML code inside it;Program codeDivClass= "CSS">PClass= "Rain">Test 1P> div> div class= "Rain" p> test 2p> div> If we use the find () method:var $find = $ ("div"). Find (". Rain");Alert ($find. HTML ()); The output will be:If you use the filter () m
JQuery visibility filter: hidden and: visibility usage example
This document describes the usage of jQuery visibility filters: Den den And: visibility. Share it with you for your reference. The specific analysis is as follows:
: Hidden
Matches all the invisible elements. If the css visibility attribute is used to make the elements do not show but occupy space, th
each matching element.$ ("Li"). each (function (index) {Console.log (Index + ":" "+$ (This). Text ()");}); Loop Each Li prints the index value of each Li and the corresponding content.$ (document.body). Click (function () {$ ("div"). each (function (i) {if (this.style.color! = "Blue") {This.style.color = "Blue";}else{This.style.color = "";}});}); When you click on the document to determine whether the color of each div text is not blue, if not, then it becomes blue, if it is removed.. End ()Ter
This example describes the jquery Form object attribute filter selector usage. Share to everyone for your reference. The specific analysis is as follows:
More about jquery selector Interested readers can view the site topics: "jquery Selector Usage Summary"
I hope this article will help you with your
This article mainly introduced the jquery Content Filter selector Usage, the example analysis: Contains (),: Has (),: Empty (),:p arent and so on content filter Selector's use skill, needs the friend to be possible to refer to under
This example describes the jquery content filter
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service