简体   繁体   中英

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

We need to fix the quotes around your identifier.

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM