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

Usage examples of parentsUntil() method in jQuery_jquery

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

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

This method searches all ancestor elements of the matching element until it encounters an element that matches an expr expression, DOM element, or jQuery element.
Obtaining the collection of ancestor elements can be filtered through filter expressions.

Note: Ancestor elements do not contain elements matching expr expressions, DOM elements or jQuery elements.

Grammar:

Grammar 1:

Copy code The code is as follows:
$(selector).parentsUntil(expr,filter)

Parameter list:

Parameter
参数 描述
expr 可选。用于筛选祖先元素的表达式。
filter 可选。用于对取得的祖先元素集合进行筛选。
Description
expr Optional. Expression used to filter ancestor elements.
filter Optional. Used to filter the obtained collection of ancestor elements.

Example:

Example 1:

Copy code The code is as follows:






Script Home





& Lt; div & gt; script house welcome you & lt;/div & gt;
          

                                                                                                                                                                                                                                                                                                                           & Lt; li & gt; javascript area & lt;/li & gt;
                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                       & Lt; li & gt; javascript area & lt;/li & gt;
                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                       






Example 2:





Copy code

The code is as follows:







脚本之家




   

       
脚本之家欢迎您

       

           

                   
  • HTML专区

  •                
  • Javascript专区

  •                
  • Div CSS专区

  •                
  • Jquery专区

  •            

           

                   
  • HTML专区

  •                
  • Javascript专区

  •                
  • Div CSS专区

  •                
  • Jquery专区

  •            

       

   



语法二:

复制代码 代码如下:
$(selector).parentsUntil(element,filter)

参数列表:

参数
参数 描述
element 可选。用于筛选祖先元素的DOM元素或者jQuery元素
filter 可选。用于对取得的祖先元素集合进行筛选。
描述
element 可选。用于筛选祖先元素的DOM元素或者jQuery元素
filter 可选。用于对取得的祖先元素集合进行筛选。

Example:

Example 1:

Copy code The code is as follows:






Script Home





& Lt; div & gt; script house welcome you & lt;/div & gt;
         

                                                                                                                                                                                                                                                                                                                           & Lt; li & gt; javascript area & lt;/li & gt;
                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                       & Lt; li & gt; javascript area & lt;/li & gt;
                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                       






Example 2:





Copy code

The code is as follows:







脚本之家




   

       
脚本之家欢迎您

       

           

                   
  • HTML专区

  •                
  • Javascript专区

  •                
  • Div CSS专区

  •                
  • Jquery专区

  •            

           

                   
  • HTML专区

  •                
  • Javascript专区

  •                
  • Div CSS专区

  •                
  • Jquery专区

  •            

       

   



希望本文所述对大家的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