sessionStorage: 10 different items with the same name

1

Friends, I'm doing a sessionStorage for 10 items. I'm counting every click I make on a div and I'm adding a number. so that's fine, but let that number go back to zero when I click on each of the next items. Follow the code;

<div class="element-item idade1 etaria" data-category="etaria"  onClick="addIdade(1);">
<div class="element-item idade1 etaria" data-category="etaria"  onClick="addIdade(2);">

etc.

and JS:

    function addIdade(idade) {
if (sessionStorage.clickcount) {
    sessionStorage.clickcount = Number(sessionStorage.clickcount) + 1;
} else {
    sessionStorage.clickcount = 1;
}
document.getElementById("idade"+idade).innerHTML =  + sessionStorage.clickcount;
sessionStorage.removeItem("conforto");
}

Why this? For when I click on the next item, obviously the value of the "clickcount" variable stored in sessionStorage already appears. Eg: I click 4 times at age 1 (goes from 0 to 4) and then once at age9 it starts at 5 and I want it to start from 0 again.

Thank you for your help!

    
asked by anonymous 27.06.2016 / 19:38

0 answers