开发者

jQuery: Get tag inside element with class

<div id="yes">
  <div class="wr开发者_开发技巧apper">
    <something>...</else>
    <p>foobar</p>
  </div>
</div>

I want to get the p-tag to append a classname

$("div.wrapper", "#yes").addClass("newClassName");

But where to add the "p"?


Try

$("div#yes > div.wrapper > p").addClass("newClassName");

Here is a jsFiddle demo


This can be achieved by the folowing code:

$("#yes div.wrapper p").addClass("newClassName");

This code gets any p-tag within any div with the class "wrapper" which is located in an element with the id "yes".


$(".wrapper").find("p").addClass("newClassName");


$("#yes").find("p").addClass("newClassName");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜