I have a Codepen https://codepen.io/Jonbeckner/pen/KKewOQq that I am working on. I have 2 click counters that displays an overall total in a box below the click counters. I have placed a button within, that I’d like to have save the total to the corresponding day of the week. I know how to add an event listener for the button but beyond that I am still learning JS.
My ask is this: when
<button class=" button button-save">
Save Total
</button>
is clicked save the overall total
<p>Total Units =
<span id="total-units">
0
</span>
to the corresponding day of the week. The total for Monday would display under M Tuesday under T and so forth.
I grabbed the current click counter from Codepen and have added to and modified it to my need thus far. I am still learning JS so please excuse my beginner knowledge.
>Solution :
With no framework, just plain HTML+JS, you can change text of an element in response to a button click like this, by setting its innerText.
document.getElementById('save').addEventListener('click', () => {
document.getElementById('total-units').innerText = '42';
});
<button id="save" class=" button button-save">Save Total</button>
<p>Total Units = <span id="total-units">0</span></p>