rocky
rocky

Reputation: 831

How to trigger click event of button after period of time in javascript

I tried to trigger click event of button after 3 mins using below javascript code

setTimeout(function(){$(‘._my_save_button’).trigger(‘click’)},180000);

Above code throws error when we run in chrome console

Uncaught SyntaxError: Invalid or unexpected token

Upvotes: 2

Views: 5371

Answers (2)

Avanthika
Avanthika

Reputation: 4182

We need to fix the quotes around your identifier.

setTimeout(function() {
    $('._my_save_button').trigger('click');
}, 3000);

Upvotes: 6

stefanomarano
stefanomarano

Reputation: 26

I think you are only missing the right css selector.

should be "#_my_save_button" in case of id="_my_save_button" or "._my_save_button" in case of class="_my_save_button":

setTimeout(function(){$("#_my_save_button").trigger("click")},180000);

Upvotes: 0

Related Questions