编辑下面的代码:【加编码】
<html> <head> <style> .ancestors * { display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px; } </style> <script src="https://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ var $findSpanElements=$("span"); $("ul").find($findSpanElements).css({"color":"red","border":"2px solid red"}); }); </script> </head> <body class="ancestors">body (great-grandparent) <div style="width:500px;">div (grandparent) <ul>ul (direct parent) <li>li (child) <span>span (grandchild)<span>span (great-grandchild)<span>span (great-great-grandchild)</span></span></span> </li> <li>li (child) <span>span (grandchild)</span> </li> </ul> </div> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂