Jump to content

Changing table color with javascript


Arcader

Recommended Posts

Hey i've been trying to change the background color of a <td> with javascript, but no success.<script type="text/javascript>document.getElementById('bg').bgcolor='green'</script><table><td id="bg"></td></table>Is there anything I did wrounge with the code?

Link to comment
Share on other sites

Use the style property instead to change it using CSS properties instead of the HTML attributes.document.getElementById('bg').style.backgroundColor='green'In Javascript, the hyphenated CSS properties like background-color are non-hyphenated and camelcased, like backgroundColor. Also try changing the color name "green" to the hex code, either #00FF00 or #0000FF, I can never remember if that's RGB or RBG.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...