jquery-traversing

jQuery get id of element by searching for it by class

℡╲_俬逩灬. 提交于 2019-11-30 03:35:48
问题 This is my html : <div id="my_box_one" class="head-div"> <div> <div class="some_box">a</div> <div class="some_box">b</div> </div> </div> I want to get the ID of the parent div("#my_box_one") using the class of that div(".head-div") $(document).ready(function(){ $(".some_box").click(function(){ var abc = $(this).parentsUntil(".head-div").attr("id"); // also tried $(this).parent(".head-div") -- same effect alert(abc); // Shows as Undefined }); }); I can do the following and it will work okay,

Skip recursion in jQuery.find() for a selector?

笑着哭i 提交于 2019-11-29 07:15:45
TL;DR: How do I get an action like find(), but block traversal (not full stop, just skip) for a certain selector? ANSWERS: $(Any).find(Selector).not( $(Any).find(Mask).find(Selector) ) There were many truly great answers, I wish I could some how distribute the bounty points more, maybe I should make some 50 pt bounties in response to some of these ;p I choose Karl-André Gagnon's because this answer managed to make findExclude unrequired in one, slightly long, line. While this uses three find calls and a heavy not filter, in most situations jQuery can use very fast implementation that skips

Skip recursion in jQuery.find() for a selector?

橙三吉。 提交于 2019-11-28 00:58:45
问题 TL;DR: How do I get an action like find(), but block traversal (not full stop, just skip) for a certain selector? ANSWERS: $(Any).find(Selector).not( $(Any).find(Mask).find(Selector) ) There were many truly great answers, I wish I could some how distribute the bounty points more, maybe I should make some 50 pt bounties in response to some of these ;p I choose Karl-André Gagnon's because this answer managed to make findExclude unrequired in one, slightly long, line. While this uses three find