parent()获取的是指定元素的所有唯一父元素的集合,而且是直接父元素,不包括祖先元素;
parents()获取的是指定元素的所有祖先元素的集合。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="./js/jquery.js"></script>
<title>Document</title>
</head>
<body>
<div class="test1">
<div class="test2">
<div class="test3">11</div>
</div>
</div>
<div class="test1">
<div class="test2">
<div class="test3">22</div>
</div>
</div>
</body>
<script>
console.log($(".test3").parent());
console.log($(".test3").parents());
</script>
</html>
控制台输出↓