I'm a beginner when it comes to Javascript. With click, the number should increase by one. I don't want to use tag IDs here, but as if made in class.
I am trying to give you a quick overview of the ClapsCounter here. The clap clicks are stored in the respective _ClapsCounter.txt file and the vote is stored in the browser localStorage as "applaudiert". Click on the counter to increase the value of all divs with the class "ClapsCounterCount".
let clicks = document.querySelectorAll('.ClapsCounterTrigger');
let count = Array.from(document.querySelectorAll('.ClapsCounterCount'));
let TxtContainer = Array.from(document.querySelectorAll('.ClapsCounterTxtContainer'));
let beforClick = "<span class=\"muted italic\">Applaudieren Sie diesen Artikel</span>";
let afterClick = "<span class=\"success italic\">Danke für Ihren Applaus!</span>";
let alreadyClick = "<span class=\"warning italic\">Danke, Sie haben schon applaudiert!</span>";
let i;
TxtContainer.forEach(i => i.innerHTML = beforClick);
// something wrong here!?
// take the current number from the .ClapsCounterCount
let plus = count.forEach(i => i.innerHTML);
for (let i = 0; i < clicks.length; i++) {
clicks[i].onclick = function () {
// after the click increase the current click number with 1
count.forEach(i => i.innerHTML = ++plus);
TxtContainer.forEach(i => i.innerHTML = afterClick);
}
}
<div class="ClapsCounter">
<h4>View @media (min-width: 960px)</h4>
<p><span class="ClapsCounterCount">123<!-- '.$count.' --></span> <span>Applause erhalten</span></p>
<p class="ClapsCounterTxtContainer"></p>
<button class="ClapsCounterTrigger">Count +1 Button</button>
</div>
<div class="ClapsCounter large">
<h4>View @media (min-width: 1200px)</h4>
<p><span class="ClapsCounterCount">123<!-- '.$count.' --></span> <span>Applause erhalten</span></p>
<p class="ClapsCounterTxtContainer"></p>
<button class="ClapsCounterTrigger">Count +1 Button</button>
</div>
Wrong with these lines !?
// something wrong here!?
// take the current number from the .ClapsCounterCount
let plus = count.forEach(i => i.innerHTML);
// after the click increase the current click number with 1
count.forEach(i => i.innerHTML = ++plus);
expected output before click
123
expected output after click
124
Update & Solved:
Thanks for your the answer from T.J. Crowder.
The line
count.forEach (i => i.innerHTML = ++ plus);
with this addition
count.forEach (element => element.innerHTML = parseInt (element.innerHTML, 10) + 1);
solved my problem.