0

I have a sample

my JS code sample:

$('.owl-next, .owl-prev').on("click", function() {
    alert("1");
});

There is a click event on two buttons, the problem is that these two div's configure consecutively, and the event I need doesn't work.

I need a suggestion how to make the click event on the two buttons work, even if the buttons appear later.

My javascript code uploads too quickly.

DhruvJoshi
  • 16,585
  • 6
  • 37
  • 57
Cristi
  • 481
  • 4
  • 18

1 Answers1

2

Use document.ready(). It won't set the code unless the site content and it's components are fully loaded.

Note: this solution doesn't work for asynchronous calls, used for dynamical adding elements into DOM. If you want to add your elements dynamically, check following link: Event binding on dynamically created elements?


$(document).ready(function() {
  $('.owl-next, .owl-prev').on("click", function() {
    alert("1");
  });
});
Community
  • 1
  • 1
kind user
  • 34,867
  • 6
  • 60
  • 74