Skip to content
Advertisement

Trying to update the innerText of an HTML element when a button is clicked in JavaScript

enter image description here

Hey guys. I’m creating an installation widget where the command to run changes depending on the buttons that are clicked (Build version and OS version)

I want the command text at the bottom to change when a user changes their build to Preview or LTS and so on. My logic is that it checks to see if the button has the “colorText” css style enabled, which will tell the program to change the innertext of the “Run this Command” part.

Heres my code:

JavaScript
JavaScript

I havent worked with vanilla JavaScript in a long time so I’ve been trying to get familiar with it again. I would love some help on this issue! Thank you!

Advertisement

Answer

You used the operator

===

which will compare the values. To assign a value use

command.innerText = ‘Something’;

Then you commandChange function will run once instead of every click event. You should put the function inside the click event.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement