Question

Working on a slideshow and there's a callback for mouseover called panelMouseOver. I can log the event.index in my Dev Console, but I'm a little too noobish with jQuery to know how to put that number within the selector. This is what I have which does not work, but should give you an idea about what I'm trying to do. "data-index" is an attribute on the slide divs with a number for each one. Thanks!

            panelMouseOver: function(event) {
                console.log(event.index);
                $("div[data-index='event.index'] h2").fadeOut();
            },
Était-ce utile?

La solution

You're really close, you just need to do some concatenation:

$('div[data-index="' + event.index + '"] h2').fadeOut();

If this event is attached to the div in question, though (I can't be sure from the info in the question), it may be much simpler:

panelMouseOver: function(event) {
    $(this).find("h2").fadeOut();
},

...or similar.

Autres conseils

Use this

$("div[data-index='" + event.index + "'] h2").fadeOut();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top