Lepper Posted February 26, 2007 Share Posted February 26, 2007 I use the following but it doesn't work document.getElementById("myThing").style.background-color = "yellow"; However, this style property does work: document.getElementById("myThing").style.display = "block"; Am I accessing wrong the property background-color?Thanks! Link to comment Share on other sites More sharing options...
pulpfiction Posted February 26, 2007 Share Posted February 26, 2007 Try thisdocument.getElementById('myThing').style.backgroundColor = '#FF0000';Reason your code is not working is, Javascript considers hyphen as subtraction (minus) "background-color" Link to comment Share on other sites More sharing options...
aspnetguy Posted February 26, 2007 Share Posted February 26, 2007 just to explain why.Javascript doesn't allow (-) in member names ( a member is a property or function of an object) so you need to use camleCase.You will run into a problem with the float property aswell so you will need to do something like the following. //float is a keyword in other browsers besides IE so you have to account for thatif(navigator.appName == "Microsoft Internet Explorer") document.getElementById('myThing').style.float = 'left';else document.getElementById('myThing').style.cssFloat = 'left'; Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now