<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="box">
<div>
<div class="aaa">
<p class="aaa">
<span>后代元素</span>
</p>
</div>
</div>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
var $span = $('span');
// 查找所有的祖宗元素
var $parents = $span.parents();
console.log($parents);
// 查找祖宗元素里离span最近的的类名为aaa的元素
var $aaa = $span.closest('.aaa');
console.log($aaa);
</script>
</body>
</html>