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.