Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is my code implementation so far: 

if(document.getElementById('button').clicked == true)

{

   alert("button was clicked");

}

HTML:

<input id="button" type="submit" name="button" value="enter"/>

Can anyone tell me how to check whether a button is clicked in JavaScript? 

1 Answer

0 votes
by (19.7k points)

Below code will alert you, when it’s clicked: 

document.getElementById('button').onclick = function() {

   alert("button was clicked");

}​;​

If you want to track this click event handler, you can set variable++ if you want to count the number of clicks. Check here to see an example. 

Interested in Java? Check out this Java tutorial by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...