Yash
Yash

Reputation: 27

jquery-ias jQuery doesn't work for loaded items

Here is the problem, I understood that for new items we should add the rendered event, here is my code but jQuery still doesn't work for new items, what I'm doing wrong ?

$( document ).ready(function() {
$('.dwn').hover(function() {
  $(this).parent().siblings().css({
    'opacity': '0.3'
  })
}, function() {
  $('.view').css({
    'opacity': '1'
  })
});
});

With rendered :

 ias.on('rendered', function(items) {
    var $items = $(items);
    $items.each(function() {
    $('.dwn').hover(function() {
      $(this).parent().siblings().css({
        'opacity': '0.3'
      })
    }, function() {
      $('.view').css({
        'opacity': '1'
      })
    });
    });
    });

Thanks for your help !

Upvotes: 0

Views: 117

Answers (1)

Joint
Joint

Reputation: 1226

You can use event listener on element that contains items you want to do something on hover it. The biggest and universal handler can be $('html'). You must explode your .hover() to two events listeners. Modified code below:

$(document).ready(function() {
  $('html').on('mouseover', '.dwn', function() {
    $(this).parent().siblings().css({
      'opacity': '0.3'
    });
  });
  $('html').on('mouseout', '.dwn', function() {
    $('.view').css({
      'opacity': '1'
    });
  });
});

Upvotes: 1

Related Questions