开发者

Jquery - Get parent id (parent must have a special Classname)

i have the "c_500" id and i need the id from next parent with the 开发者_JAVA技巧classname "pp".

i search something like ...

$('#c_500').getNextParentWithClass('pp');

html

 <div id="d_548" class="pp">

    <div class="class_ft">

      Blub<hr />
      <div id="here">content</div>
      <div id="c_500">content</div>

    </div>

  </div>

Thanks in advance! Peter


You can use .closest() with a .class selector to get the element, then just grab the ID, like this:

$('#c_500').closest('.pp').attr('id');

You can give it a try here, .closest() is the same behavior as .parents('pp:first'), walking up the parents until it finds the first one that matches the selector.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜