在 jQuery 中查找后代元素时未获得所需的输出



我没有通过给定的代码获得彩色输出。

<html>
<head>
<title>the title</title>
   <script type="text/javascript" 
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   $(document).ready(function() {
      $("p").find("span").addClass("selected");
   });
   </script>
   <style>
      .selected { color:red; }
  </style>
</head>
<body>
   <p>This is 1st paragraph and <span>THIS IS RED</span></p>
   <p>This is 2nd paragraph and <span>THIS IS ALSO RED</span></p>
</body>
</html>

我错过了什么吗?谢谢

使用这个: http://jsfiddle.net/gaHhv/1/

 <script type="text/javascript" src="http://code.jquery.com/jquery-1.3.2.js"></script>

虽然you should use latest jquery.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>

你在控制台日志中得到什么吗?代码很好,看到它在这里工作,确保你的 Jquery src 是正确的

$("p").find("span").addClass("selected");​

JS 小提琴

最新更新