Home > Enterprise >  How to change color of button text on click
How to change color of button text on click

Time:04-22

I have a button that, when clicked, changes its background color, and the text inside turns bold. What i'm trying to do, is to make the text become bold AND white.

Currently i have:

btn.addEventListener("click", () => {
  btn.style.backgroungColor = 'white'
  btn.style.fontWeight = 'bold'
})

Is there a way to do that, using pure JS? If not, what i the best way to do so? I've tried using btn.style.color = "white" , but it makes my border white as well, so i need other solutions, or a way to undo the changes on the button border.

CodePudding user response:

You had a typo backgroundColor, and for the fontWeight set a number not bold like 900. also, you forgot semicolons.

btn.addEventListener("click", () => {
  btn.style.backgroundColor = 'white';
  btn.style.fontWeight = '900';
})

CodePudding user response:

Seems like you misspelled "backgroundColor"

btn.addEventListener("click", () => {
  // original - btn.style.backgroungColor = 'white'
  btn.style.backgroundColor = 'white';
  btn.style.fontWeight = '900';
})
  • Related