For example if I use display.textContent = “Hello”; in a function later in my code it won’t update the text. Does anyone know why this is the case? I want it to update in my function.
Without context is a pretty vague, but you can always be able to get an element and set its contexts as:
document.getElementById('example').textContent = "This is some text";
With a basic event listener
document.getElementById(whatever).onclick = function() {
document.getElementById(theTextIWantToChange).textContent = "This is some text";
};
Hope it gives you a good start
The set text is within a function which is called by a click event.
click event -> call to function -> inside function textContent statement doesn’t work.
This is a personal project I’m working on. JavaScript is such garbage compared to Java, C++ and Python for me so far. Not enjoying this language.
post your code before calling JS garbage.
I solved this issue on my own. Thanks.
I created my own callback function to update the value I needed. Previously when the textContent was in another function that was called by an event, it wouldn’t change my textContent. It just ran all the other code within that function’s block. JavaScript presented no errors and simply didn’t run my statement which was quite frustrating.