Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call function javascript first second

I want to make it so that on a first click i call one function for javascript, and on a second click i call another function for javascript. How can that be?

Basically i press on this image, it calls this function, if i press it again it calls another function. First then second.

Using html

like image 442
soniccool Avatar asked Dec 16 '22 07:12

soniccool


1 Answers

  <script>
    var clicked = false;

    function doSomething()
   {
      if(clicked)
     {
       alert(2); 

     }
    else
    {
       alert(1); 

    }
   clicked = !clicked;
}
  </script>
</head>
<body>
  <p id="hello" onClick="doSomething();">Hello World</p>
</body>

See exmple here http://jsbin.com/uzivuj

like image 173
Daveo Avatar answered Dec 27 '22 06:12

Daveo