I'm trying to get my Javascript to toggle text in a div to bold and back but I can't find the function to do this. Can anyone help?
Thanks very much
Printable View
I'm trying to get my Javascript to toggle text in a div to bold and back but I can't find the function to do this. Can anyone help?
Thanks very much
I don't know javascript, that is, I don't know the exact syntax to use, but I've seen examples of JavaScript controlling CSS-attributes.
Somethin along these lines
If that's not the correct function and/or syntax, I'm sorry, but it should give you something to go on.Code:getElementByID("div").style.font-weight: bold;
It's almost correct, but you need to translate the names of the CSS properties. Every - in the name gets removed and the next character becomes uppercase, e.g.
font-weight -> fontWeight
And of course you need JavaScript-style assignment, that is
document.getElementById('thediv').style.fontWeight = "bold";
There are far more complicated ways to do other interesting things too, but they don't work in IE so they're usually not interesting.