0

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?

Lightness Races in Orbit
  • 369,052
  • 73
  • 620
  • 1,021
Mathias
  • 334
  • 3
  • 5
  • 21
  • 2
    you could just pass `this` as a second parameter to `$`. Like: `$('.another-class', this);` – Yoshi Nov 08 '11 at 09:58

3 Answers3

5

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.

Matt
  • 72,564
  • 26
  • 147
  • 178
2
$('.some-class').hover(function() {
    $(this).find('.another-class'); 
})
gion_13
  • 40,487
  • 10
  • 96
  • 107
2

This Keyword represent Object

You need to try this

jQuery(".another-class", this);

More detail

Community
  • 1
  • 1
Rupesh Pawar
  • 1,857
  • 12
  • 17