Reputation: 334
I have a Selector in a Selector. I want the inner Selector to select only those elements, that are also selected by the outer Selector. This is what my naiveté came up with:
$('.some-class').hover(function() {
$( this + '.another-class');
})
Put differently, I want the elements with with another-class
AND which are children of the element that is hovering. How do I do that?
Upvotes: 0
Views: 150
Reputation: 1917
This Keyword represent Object
You need to try this
jQuery(".another-class", this);
More detail
Upvotes: 2
Reputation: 41533
$('.some-class').hover(function() {
$(this).find('.another-class');
})
Upvotes: 2
Reputation: 75317
Use the children()
method.
$('.some-class').hover(function() {
$(this).children('.another-class');
});
This method falls under the traversal category, which allows you to select ancestors, descendants, siblings etc all from the current element.
Upvotes: 5