This paper analyzes the filter () method of jquery traversal DOM node operation. Share to everyone for your reference, specific as follows:
. Filter (selector)
This method is used to filter in matching elements according to selector expressions.Remember: You must pass in the selector expression parameter by using thi
child elements (including only the first child element) under the parent element ).3). "$ (" pre + next ")" to obtain the last sibling element following the pre element.4). "$ (" pre ~ Siblings ")" to obtain all the sibling elements behind the pre element.3. Filter SelectorFilter? You must add filtering conditions. ":" Is used to add filter conditions. For example, "$ (" div: first ")" returns the first di
Preface
PreviousArticle(The powerful basic selector and hierarchy selector of jquery selector) describes the basic selector and hierarchy selector in jquery's four types of selectors. This article will introduce the remaining two selectors: filter selector and form selector.
This article still uses the Example page in the previous article. I. Filter Selector
create a nested filter
Filters that allow you to reduce the matching elements in the collection,
//Only those parts that match the given selector. In this case,
//The query deletes any child nodes (: Has)
//that contain the class "Selected" (. selected).
. Filter (": Not (: Has (. selected))")
2. How to reuse element search
var AllItems = $ ("Div.item");
var keeplist = $ ("Div#contai
How jQuery traverses DOM node operations: filter () method, jquerydom
This article analyzes the filter () method of jQuery traversal DOM node operations. We will share this with you for your reference. The details are as follows:
. Filter (selector)
This method is used to
JQuery events --- filter selector form SelectorFilter selector for short: filter. It is actually a selector, and this selector is similar to the pseudo class in CSS3 (http://t.mb5u.com/css3/), can make does not support CSS3 of the lower version of the browser can also support. Like regular selector, jQuery provides ma
gets the specified elementSyntax: Children (expr); Gets the resource for the specified element, and expr filters the criteria for the child element$ ("div"). Children (". P2"); 12, closest () starts with the current element and returns the first match to the parent element that matches the condition$ ("span"). Closest ("P", "div"); 13. Find () finds child elements from the specified elementSyntax: Find (Expr|obj|ele) expr: match expression | obj for matching
After a night of searching and finishing, finally sorted out a set of the most comprehensive jquery selection filter method. All the code has been tested.
First HTML code
Copy Code code as follows:
HTML Code
JS Code
1.DOM object and jquery wrapper set
1. by document.getElementById (), Document.getelementsbyname () is a DOM object or
Examples of filter method usage in jquery
This article mainly introduces the usage of the filter method in jquery. The example analyzes the function of the filter method and compares the difference with the find method. For more information, see
This example describes the
First, what is jquery?jquery is a very good JS framework. Is the use of JS in the more commonly used methods to encapsulate the underlying. The slogan is "Write Less,do more".Second, how to use jquery? (The whole idea of using jquery)1. After the page has finished loading2. Find objects3. Perform the event you want4. D
Select all elements that are not visible and use the show () method in jquery to display them and set their background color to # BBFFAA
Select all the text-hidden fields and print their values
Attribute Filter Selector
The filter rule for the attribute filter selector is to get the corresponding element through t
This article mainly introduces information about node operation methods such as each (), find (), and filter () in jQuery. It is very helpful and has reference value. If you need it, refer to section 1. each (callback)
Official explanation:
Returned value: jQuery
Overview
Execute a function using each matching element as the context.
This means that each time t
specified elementSyntax: Children (expr); Gets the resource for the specified element, and expr filters the criteria for the child element$ ("div"). Children (". P2"); 12, closest () starts with the current element and returns the first match to the parent element that matches the condition$ ("span"). Closest ("P", "div"); 13. Find () finds child elements from the specified elementSyntax: Find (Expr|obj|ele) expr: match expression | obj for matching jquery
the third and sixth three into red.. Filter (Element)Element one or more DOM elements match the current collection of elements.$ ("div"). Filter (". Mddle"). CSS ("Border-color", "Red");Gets the element in the div that contains the. Middle selector, turning its background red.. Filter (JQuery object)
The difference between the filter () function and the Find () function of jquery:In jquery, many functions are very convenient to use, while some functions are very close to each other, so it is easy to create a certain error operation.The filter () function and the Find () function have the same filtering effect, and the difference between them is described belo
Research on the use of filter (fn) in jquery, jqueryfilter
The official description of filter (fn) in jquery is as follows:
Filter out the element set that matches the returned value of the specified function. This function calculates each object once (as '$. each '). if the
JQuery filter selector Usage AnalysisThis article mainly introduces the usage of jQuery filter selector. examples show the usage skills of common filter selector such as first, last, odd, and even, which is of great practical value, for more information, see
This document
Find () overviewSearches for all elements that match the specified expression. This function is a good way to find out the descendant elements of the element being processed. All searches are done using jquery expressions. This expression can be written using Css1-3 's selector syntax.ParametersExprStringV1.0 Expression for Lookup JQuery Object ObjectV1.6 A jquery
Filter (), not ():Scripttype= "Text/javascript">$ (document). Ready (function() {//Output HelloAlert ($ ("P"). Filter (". Selected"). HTML ());//How is the output?Alert ($ ("P"). Not (". Selected"). HTML ());});Script> Head>Body> Pclass= "Selected">HelloP>P>How is it?P>a new challenge is to select only one particular element from a set of similar or identical elements.
(). Size ();//Returns the number of child nodes (including text)$ (' li '). Filter ('. Red '). CSS (' background ', ' #ccc ');//Select Li's class as the red element$ (' li '). Filter ('. Red,: First,: Last '). CSS (' background ', ' #ccc '); Added a choiceSpecial requirements function return$ (' li '). Filter (function () {return $ (this). attr (' class ') = = '
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.