Reputation: 566
How can I get a sub element from $(this)?
So for example, how would I target a span element within the this object?
Upvotes: 2
Views: 220
Reputation: 166031
You could use the find
method:
$(this).find("span");
That will find all span
elements that are descendants of the element referred to by this
.
If you only care about direct children you could use children
instead:
$(this).children("span");
Alternatively, you could use this
as the context to a selector:
$("span", this);
Yet another solution would be required if this
was a jQuery object that contained a set of sibling elements (so the span
is not a descendant). In that case, you would need filter
:
$(this).filter("span");
Upvotes: 5