I need to attach a dynamic click on a dynamically added element .may inside a setTimeout function. How can I use setTimeout on this element?
$('.btn').on('click', function (){
setTimeout(function(){
$('.may').click();
}, 3000);
});
I need to attach a dynamic click on a dynamically added element .may inside a setTimeout function. How can I use setTimeout on this element?
$('.btn').on('click', function (){
setTimeout(function(){
$('.may').click();
}, 3000);
});
To my understanding this adds an event listener for an item that is has the btn class on it. This code is run on document.ready, I assume. Since the element isn't loaded when the DOM loads, this listener doesn't attach to anything.
What you could do is have this event listener code run after the element is added to the page. Encapsulating it in a function and running that function linearly after the element is done being added to the page should do the trick.