I have a button that looks like this:
HTML:
<button type="button" id="top_skin" onclick="theme()">Theme: <span id="dark">Dark</span>/<span id="light">Light</span></button>
CSS:
#top_skin{display:inline;
float:right;
margin:5px 15px 5px 5px;
padding: 0px 5px 0px 5px;
height:20px;
min-width:140px;
background:grey;
cursor:pointer;
border-radius:5px;
overflow:hidden;
}
#dark{font-weight:bold;}
I want JavaScript to switch the font-weight of the words "Dark" and "Light" so that when I click the button the word "Light" gets bold and "Dark" gets normal. And when I click again I want "Dark" to be bold and "Light" to be normal. But I can't make it work. The funny thing is that I can create a function that do the same thing, but with color in stead of font-weight.
The code that works but changes color instead of font-weight:
function theme(){
var dark = document.getElementById('dark');
var light = document.getElementById('light');
if(light.style.color !== "red"){
light.style.color="red";
dark.style.color="black";
}else{
dark.style.color="red";
light.style.color="black";
}}
The code that I thought would do the same thing, but with font-weight:
function theme(){
var dark = document.getElementById('dark');
var light = document.getElementById('light');
if(light.style.fontWeight !== "bold"){
light.style.fontWeight="bold";
dark.style.fontWeight="normal";
}else{
dark.style.fontWeight="bold";
light.style.fontWeight="normal";
}}
Thank you!
Edit:
Now this time when I try it it seems to work just fine for me too. I suppose there have been a typo somewhere. Thank you all for your answers, and I am sorry I took your time!