Do action when two buttons are clicked one after another
Hello I am trying to make an alert when two buttons are clicked one after another but I have a problem, the following code doesn't work
- <script>
- var hasBeenClicked = false;
- $(document).ready(function() {
- $("#submit1").click(function(){
- hasBeenClicked = true;
- });
- var hasBeenClicked2 = false;
- $("#submit2").click(function(){
- hasBeenClicked2 = true;
- });
- if(hasBeenClicked==true && hasBeenClicked2==true){
- alert('Alert');
- }
- });
- </script>
- <body>
- <button type="button" id="submit1">Click Me!</button>
- <button type="button" id="submit2">Click Me!</button>
-
-
- </body>
I don't understand why it doesn't work and is there any other more optimal solution to the code I wrote?