parent([expr]) :
取得一个包含着所有匹配元素的唯一父元素的元素集合。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/jquery-3.3.1.js"></script>
</head>
<body>
<div>
<a id="link" href="http://www.baidu.com">百度</a>
</div>
<script>
console.log($("#link").parent()[0]);
</script>
</body>
</html>
(仅在console页面中打印出一个“<div>...</div>”)
parents([expr]) :取得一个包含着所有匹配元素的祖先元素的元素集合(不包含根元素)。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/jquery-3.3.1.js"></script>
</head>
<body>
<div>
<a id="link" href="http://www.baidu.com">百度</a>
</div>
<script>
$("#link").parents().each(function(){
console.log(this);
});
</script>
</body>
</html>
console页面显示情况: