I´m trying to use JS to get the arrow buttons to increment and decrement. I keep getting a NaN value, and I have no idea how to convert it to a number in order to make it possible for the function to work. Any ideas?
is incrementing numberUp, which is a DOM node. You want to get the innerText of that (maybe), and parse the number out of that, maybe with parseFloat() or parseInt().
Thank you for the reply. I did what you said, and now I´m getting the correct numbers on the console. But textContent doesn´t seem to be writing the new values. Any ideas?
var breakButton= document.getElementById("break-increment");
var numberUp= document.getElementById("break-length").innerText;
breakButton.addEventListener("click", function(){
numberUp++;
console.log(numberUp)
numberUp.textContent=numberUp;
});
Still won´t work. To make matters worse, now I´m getting a correct value (the first time = 6) and after that a NaN. I´m getting because after setting InnerText the value becomes a string and thus can´t be added up. Any thoughts? Sorry for being so annoying.
var breakButton= document.getElementById("break-increment");
var numberUp= document.getElementById("break-length").innerText;
breakButton.addEventListener("click", function(){
numberUp++;
console.log(numberUp)
numberUp=numberUp.innerText;
});
Of the span element, of course. I´m guessing type coersion is an issue here, so I parsed the value of numberUp to an Int. Now I´m getting a correct value (the first time = 6) and after that a NaN. And it still won´t update the value.
var breakButton= document.getElementById("break-increment");
var numberUp= parseInt(document.getElementById("break-length").innerText);
breakButton.addEventListener("click", function(){
numberUp++;
console.log(numberUp)
numberUp=numberUp.innerText;
});
The numberUp variable is set to the “break-length” ID element which is the span element in the HTML. Shouldn´t it get its value updated after numberUp=numberUp.innerText happens?