I have a button that does copy function for me with the help of JS:
<button class="js-copy-btn" data-clipboard-target=".cb-target-1">E</button>
<p class="cb-target-1">SOME TEXT</p>
var clipboard = new ClipboardJS('.js-copy-btn');
And i want to include the function that counts how many times do i press that button with this:
<button class="btn">Button</button>
<span class="cnt">0</span>
document.querySelectorAll('ul .btn')
.forEach(function(el){
el.onclick = function() {
let cnt = this.closest('li').querySelector('.cnt');
cnt.innerText = parseInt(cnt.innerText, 10)+1;
};
});
Please help me realize if it is possible to have two classes for one button, taking that there will be a lot of buttons and each button should have the count option, so far I was not able to find any solution. Sorry if the question is stupid. PS. Not interested in collecting data of the buttons in the long run, that is why the count option is in html and not in the separate file. Thank you in advance.