Home > Web Front-end > JS Tutorial > Summary of jQuery filter element operations_jquery

Summary of jQuery filter element operations_jquery

WBOY
Release: 2016-05-16 17:11:32
Original
990 people have browsed it

1: eq(index) method

is used to get the Nth element. The position of this element starts from 0. The syntax format is as follows: eq(index)

Get the third table and set its background color to "#FCF", the code is as follows: $("td").eq(2).css("background", "#FCF");


2: filter(expr) method

is used to filter out the set of elements that match the specified expression, and is used to narrow the scope of the match. Use commas to separate multiple expressions, then there is an "OR" relationship between multiple expressions,

The syntax is as follows: filter(expr)

$("input").filter(".sel").css("backgroud", "#FCF"); //Select the input element with the class attribute value sel and set its background color

$("input").filter(".sel, :first").css("background", "#FCF"); //Select input elements with class attribute values ​​or select elements in the current field first element and set their background color,

Separate expressions with commas


3: filter(fn) method

is used to filter out the set of elements that match the return value of the specified function. The function will internally calculate each object once (such as $:each). If the called function returns false, the element will be deleted,

Otherwise it will be retained. The syntax format is as follows: filter(fn)

Copy code The code is as follows:





filter(fn) usage





     >

    How are you?






    Assume that the child element does not contain the ol element, and Set the font color of this element to blue.






4: has(expr) method

is used to retain elements that contain specific descendants and remove elements that do not contain the specified descendants. This method will recreate a set of matching objects from the given jQuery object. The provided selector will test the original

one by one. 🎜>

Descendants of those objects, objects containing matching descendants will be retained, the syntax format is as follows:

has(expr)


Copy code The code is as follows:





has(expr)用法



   


          
          
  • 正文

  •       
  • 结尾

  •    




5: hasClass(class)

用于检查当前的元素是否含有某个特定的类,如果有,则返回true

复制代码 代码如下:





hasClass用法



  

div元素

  
div元素二




6:map(callback)方法

map(callback)方法用于将一组元素转换成其他数组(无论是否是元素数组), 可以用这个函数来建立一个列表,无论是值、属性还是CSS样式,或者其他特别形式,

都可以用$.map()来方便的建立,语法格式如下:

map(callback)

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