The difference between lookup parents and closest methods in jquery _jquery

Source: Internet
Author: User

Return value The former can return multiple elements or can only return 0 or one

The time of stopping is different from the former is all the superior element that is always to the root is usually the body the latter is to know the discovery, found that one stopped

The first element is different from the parent element the latter is starting from itself

The code is as follows:

Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Find parent Element </title>
<script src= "Scripts/jquery-1.4.1.js" type= "Text/javascript" ></script>
<body>
<div class= "Divclass" id= "Div1" style= "width:300px;height:150px"; >
<div style= "width:200px;height:100px; margin-top:10px;margin-left:30px; " >
<p>
Add borders to Ancestors
</p>
</div>
</div>
</body>
<script>
$ ("P"). Closest ("div[id= ' Div1 ')"). CSS ("Border", "1px solid Blue");
</script>

You can try to change the closest to parents.

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.