Cómo conseguir un selector usando esto

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?

preguntado el 08 de noviembre de 11 a las 09:11

you could just pass this como segundo parámetro para $. Como: $('.another-class', this); -

3 Respuestas

Utiliza children() Método.

$('.some-class').hover(function() {

This method falls under the traversal category, which allows you to select ancestors, descendants, siblings etc all from the current element.

respondido 08 nov., 11:13

$('.some-class').hover(function() {

respondido 08 nov., 11:13

This Keyword represent Object

You need to try this

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

Más detalle

contestado el 23 de mayo de 17 a las 15:05

It should be noted that this is looking for descendants, not just children. - Matt

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.