Вопрос

I have a set of divs built like this with display:none; on .imageholder:

<div class="parent">
<div class="imageholder">
    <img src="img.jpg">
</div>
<div class="parent">
    <div class="imageholder">
        <img src="img.jpg">
    </div>
</div>
<!--and so on...-->

and this jQuery:

$('.parent').hover(
function() {
    $('.imageholder').fadeIn('slow');
},function() {
    $('.imageholder').fadeOut('slow');
}

); When I hover the .parent div all related parent divs are displaying the image.

How can I make the hover state to work just for the actual hovered parent element? Thanks!

Это было полезно?

Решение

function () {
    $(this).find(".imageholder").fadeIn("slow");
}

You can use this in the .hover callback to refer to the hovered (parent) element.

Другие советы

$('.parent').hover(function () {
    $(this).find(".imageholder").fadeIn("slow");
});

Try this fiddle you can use .find() method for to point div.

Just like

$(document).ready(function()
                  {
                      $('.parent').hover(function() {
                    $(this).find('.imageholder').fadeIn('slow');
              },function() {
                   $(this).find('.imageholder').fadeOut('slow');
              })
                  });
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top