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
  • 378,754
  • 76
  • 643
  • 1,055
Mathias
  • 334
  • 3
  • 5
  • 22
  • 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
  • 74,352
  • 26
  • 153
  • 180
2
$('.some-class').hover(function() {
    $(this).find('.another-class'); 
})
gion_13
  • 41,171
  • 10
  • 96
  • 108
2

This Keyword represent Object

You need to try this

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

More detail

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