0

I have a javascript function to check for hover on image and display a delete button. It's working on existing thumbnails when the page first loaded, but when I upload an image and prepend the data with ajax to existing thumbnail gallery the hover function is not working to the newly added thumbnails.

Here's the script which is on the document ready

$(".del_photo").hide(); // Initially hide all buttons

$('.photo-item').hover(function(){
    $(this).find('.del_photo').fadeIn(1000);
}, function(){
    $(this).find('.del_photo').fadeOut(1000);
});

thanks

According to the link gave by Olav, here's my new code.

$(document).on({
        mouseenter: function () {
            $(this).find('.del_photo').fadeIn(1000);
        },
        mouseleave: function () {
            $(this).find('.del_photo').fadeOut(1000);
        }
    }, ".photo-item"); //pass the element as an argument to .on
fyeth fyeth
  • 93
  • 3
  • 10

2 Answers2

0

actually we need this function if we want to use function on already present class or id..here situation is different.class is adding dynamically so,use following function

$(document).on('hover','.photo-item',(function(){
Mr7-itsurdeveloper
  • 1,631
  • 2
  • 17
  • 24
-1

Try 'on', something like:

$('.photo-item').on("hover", function(){
// ...
})
JPK
  • 491
  • 5
  • 27