Jump to content

Changing table color with javascript


Arcader
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...