0

for some reason my click event on <div data-load-more></div> is triggers number of times I clicked it until I refreshed the page.

$('[data-load-more]').css('display','block').on('click.load-more', function(event){
  event.preventDefault();
  event.stopPropagation();
  alert('clicked');
});

referred here: jQuery on() stopPropagation not working? so checked the target

console.log(event.target);

and it shows the correct one which is <div data-load-more></div>

How do fix this issue. Is there a way to clear click event on the div or something?

Community
  • 1
  • 1
112233
  • 2,406
  • 3
  • 38
  • 88

1 Answers1

0

Try the following:

$('[data-load-more]').css('display','block').on('click.load-more', function(event){
  if ($(event.target).is('[data-load-more]')) {
  alert('clicked');
  }
});
madalinivascu
  • 32,064
  • 4
  • 39
  • 55