How do I add a counter to show how many times a div element has been clicked?

Ask a question
1

I am creating a basic website for a personal project. I have a div element in the code as well. When a user clicks this particular div element, I want the site to display a counter next to the div element to count how many times it has been clicked. I don’t need to save anywhere else how many times it has been clicked. Is this possible with JS and how could I do this?

I don’t know much Javascript at all, so I haven’t known what exactly to try.

I want to have a basic counter next to the element to count how many times it has been counted. Again, nothing needs to be saved a server. Also, I am not worried about how many times a user can click the div element and add another number.

offer bounty
add comment

1 Answer

1

you can with js it’s simple
var myDiv = document.getElementById("divId"),;
count = 0;
myDiv.onclick = function() {;
count += 1;
myDiv.innerHTML = "Click me: " + count;
};

add comment

Your Answer