Javascript DOM Button Click Count

Description

Javascript DOM Button Click Count

View in separate window

<!DOCTYPE html> 

<html lang="en"> 
<body> 
    <form action="" name="form1"> 
        <input type="button" name="myButton" value="Button clicked 0 times" /> 
    </form> 

    <script> 
        let myButton = document.form1.myButton; 
        let numberOfClicks = 0; /*from ww w . j  a  v  a 2  s. c om*/

        function myButtonClick() { 
            numberOfClicks++; 
            myButton.value = "Button clicked " + numberOfClicks + " times"; 
        } 

        myButton.addEventListener("click", myButtonClick); 
    </script> 
</body> 
</html> 



PreviousNext

Related