-1

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);
});
bstoney
  • 5,828
  • 5
  • 42
  • 50
Behseini
  • 5,416
  • 18
  • 60
  • 107
  • 1
    I think you just have a spelling error function() not functio() – Bibberty Dec 18 '18 at 01:05
  • With the typo fixed this works for me. Maybe if you add a snippet with some html that demonstrates the problem, it will make the issues clearer. – Mark Dec 18 '18 at 01:10
  • thanks Paul I fix the typo but the question is abot targetting dynamically added contet dynqmically – Behseini Dec 18 '18 at 01:11
  • Hi Mark please be informed that I am adding the `.may` dynamically and it os not in dom at loading time – Behseini Dec 18 '18 at 01:13
  • Hi Mark please be informed that I am adding the `.may` dynamically and it os not in dom at loading time – Behseini Dec 18 '18 at 01:13

1 Answers1

0

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.

UberMario
  • 153
  • 2
  • 12