0

I have a function

Plus() {
    document.getElementsByClassName('like hintable')[0].click(); Hide();alert ("test") ;
}

How could I run document.getElementsByClassName('like hintable')[0].click()
after two seconds run Hide() after two other seconds run alert.

Is there any way without creating 3 functions and use setTimeOut .

SK.
  • 4,174
  • 4
  • 30
  • 48
a_barsa
  • 1
  • 3
  • Why you cant create 3 functions and use `setTimeOut`? – SK. Jul 15 '15 at 07:05
  • 1
    possible duplicate of [What do I do if I want a JavaScript version of sleep()?](http://stackoverflow.com/questions/951021/what-do-i-do-if-i-want-a-javascript-version-of-sleep) – SK. Jul 15 '15 at 07:07
  • I'm trying to make code short as possible @Mike – a_barsa Jul 15 '15 at 07:14
  • Creating function for different activity is not a bad practice. U have to create different functions to achieve this. – SK. Jul 15 '15 at 07:16

1 Answers1

0

You cannot use sleep/delay/wait in a function to pause Javascript unfortunately.

You have to use setTimeout()

SO - Source 1

SO - Source 2

Community
  • 1
  • 1
SK.
  • 4,174
  • 4
  • 30
  • 48