JQuery uses the parent () parents () to look for parents or ancestor elements

Source: Internet
Author: User

$ (this). The parent (). Parent (). Parent (). Remove (). This method is looked up through the parent () level
$ (this). Parents ("div"). Remove ();//This method is to find all the parent elements and ancestor elements through the "div" to filter out the ancestors of the ancestral elements of the Div

A parent is a collection of elements that gets a unique parent element that contains all the matching elements. Parents is a collection of elements (without the root element) that has an ancestor element that contains all the matching elements.    You can filter by an optional expression. The parent made it very clear that the current element parents is the ancestor element of the current element--<HTML>      <Head></Head>      <Body>          <DivID= "Div1">          <DivID= "Div2"><P></P></Div>          <DivID= "Div3"class= "a"><P></P></Div>          <DivID= "Div4"><P></P></Div>          </Div>      </Body>      <Scripttype= "Text/javascript"src= "Jquery-1.7.1.min.js"></Script>      <Scripttype= "Text/javascript">          $("P"). parent (); //the Div2, Div3 and Div4 were obtained.        $('P'). Parent ('. A'); //obtained is Div3        $('P'). Parent (). parent (); //The acquisition is DIV1 (this is strange, but the nature of the jquery object itself determines that this is possible)        $('P'). Parents (); //the Div1, Div2, Div3 and Div4 were obtained.        $('P'). Parents ('. A'); //the Div3 was made.    </Script>  </HTML>  

JQuery uses the parent () parents () to look for parents or ancestor elements

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.