sessionStorage: 10 different items with the same name

Asked

Viewed 26 times

1

Friends, I’m doing a sessionStorage for 10 items. I’m counting every click I make on a div and we’re a number. so far so good, but that this number goes back to zero when I click on each of the next items. Follow the tickle;

<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 the 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 is that? Because when I click on the next item, obviously already appears the value of the variable "clickcount" saved in sessionStorage. By exe.: If I click 4 times in age1(goes from 0 to 4) and then once in age9 already starts in 5 and I want to start from 0 again.

I appreciate a help!

  • And if you use sessionStorage.setItem('key', 'value');

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.