2

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
rocky
  • 753
  • 2
  • 10
  • 26
  • 2
    `setTimeout(function(){$('_my_save_button').trigger('click')},180000);` .............. `‘_my_save_button’` => `'_my_save_button'` – Pranav C Balan Mar 13 '19 at 15:59
  • 2
    Your single quotes are 'weird'. Try using normal single (or double) quotes: `'` or `"`. Also, your `_my_save_button` is really nothing. If it's the id of the button, you should add the prefix `#` to that. – ZiNNED Mar 13 '19 at 15:59
  • does your button have the class or id `_my_save_button`? if it is the class, prepend it with a `.`, if id, prepend with `#`. – Matthew Varga Mar 13 '19 at 16:00
  • Looks like dublicate of https://stackoverflow.com/q/7188145/8623919 – Bijay Yadav Mar 13 '19 at 16:06

2 Answers2

6

We need to fix the quotes around your identifier.

setTimeout(function() {
    $('._my_save_button').trigger('click');
}, 3000);
Jadeye
  • 3,551
  • 4
  • 47
  • 63
Avanthika
  • 3,984
  • 1
  • 12
  • 19
0

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);
theUtherSide
  • 3,338
  • 4
  • 36
  • 35