JS DOM programs collection
JavaScript Program to Use getElementById() to count the total number clicked a button using getElementById (DOM)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>to count total number of times we clicked the button</title>
</head>
<body>
<button onclick="totalclicks();">click me</button>
<p>clicked times=<span id="count"></span></p>
<script>
var c=0;
function totalclicks()
{
c++;
document.getElementById('count').innerText=c;
}
</script>
</body>
</html>
output:-
JS program to count total clicks |