开发者

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

开发者 https://www.devze.com 2023-01-12 09:48 出处:网络
i have the \"c_500\" id and i need the id from next parent with the 开发者_JAVA技巧classname \"pp\".

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

精彩评论

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