How to subfilter a jquery object that is a subset of $ (this)
I've read the documentation over and over again and I can't figure out why this doesn't work:
From within a function calling the following:
alert($(this).parent().parent().html());
returns something similar to this:
<div class="something1">
<div class="whereThisStarted">stuff</div>
</div>
<div class="something2">stuff</div>
<div class="somethingSpecial">stuff</div>
<div class="something4">stuff</div>
I want to get "somethingSpecial". It seems to me that either of the following should work, but they both return null.
alert($(this).parent().parent().children(".somethingSpecial").html());
alert($(this).parent().parent().filter("div.somethingSpecial").html());
What's wrong with that?
thanks
0
a source to share
3 answers
You might want to try the closest function - it sounds the same as what you are trying to do:
This code should work:
alert($(this).closest(".somethingSpecial").html());
Or in case your $ (this) is inside the 'startHere' div:
alert($(this).parent().closest(".somethingSpecial").html());
+2
a source to share