首页javascriptclassjQuery Selector - 如何使用类“selected”找到每个段落的父元素

jQuery Selector - 如何使用类“selected”找到每个段落的父元素

我们想知道如何使用类“selected”找到每个段落的父元素。


<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("p").parent(".selected").css("background", "yellow");
        });
    </script>
  </head>
  <body>
          <div><p>Hello</p></div>
          <div class="selected"><p>Hello Again</p></div>
  </body>
</html>