选择某个具体层次下的子层次,比如选择有p的div:
$("div p")
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <script src="js/JQ3.3.1.js"></script> <link rel="stylesheet" type="text/css" href="css/style.css" /> <script type="text/javascript"> $(function(){ $("div p").attr("class","txt"); }) </script> </head> <body> <div id="showMsg"> <h1>test</h1></div> <div id="showMsg"> <h1>test</h1></div> <span class="temp">test</span> <span>test</span> <p class="temp">test</p> <p>test</p> <div> <p>test</p> <p>test</p> </div> </body> </html>