Home  >  Article  >  Web Front-end  >  Usage examples of has() method in jQuery_jquery

Usage examples of has() method in jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:21:501666browse

The example in this article describes the usage of the has() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:

This method retains matching elements that contain a specific descendant.
The .has() method will recreate a set of matching objects from the original jQuery object.
The method will traverse the descendants of the original object by deleting the selected parameters, and objects containing matching descendants will be retained.

Grammar structure 1:

Copy code The code is as follows:
$(selector).has(expr)

Parameter list:

参数 描述
expr 字符串选择器。

Example code:

Copy code The code is as follows:






Script Home






  • HTML Zone

  • Javascript Zone

  • Div Css Zone

  • Jquery Zone





Matches li elements containing span elements and sets the font color inside them to green.

Grammar structure 2:

Copy code The code is as follows:
$(selector).has(element)

Parameter list:

参数 描述
element 含有的DOM元素。

实例代码:

复主代码 代码如下:






脚本之家

<스크립트 유형="텍스트/자바스크립트">
$(문서).ready(함수(){
  $("li").has(document.getElementsByTagName("span")).css("color","green");
})




 

       
  • HTML专区

  •    
  • Javascript专区

  •    
  • Div Css专区

  •    
  • Jquery专区

  •  



Statement:
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