Jump to content

changing a class attribute


hgmme@wa

Recommended Posts

What's it take to use "document.getElementById('theID')" to change the class on something. In this case it happens to be an <h2> tag. I'd just change the specific styling I want to change but I don't want change it with javascript do to the differences in the location of the css file, the javascript file, and the image. Cause you see I know exactly were the image will be in relation to the css file but not always the relation between the javascript and the image. Make sense?

Link to comment
Share on other sites

Make sense?
Not really. But to access the styles applied to an element you can use the style property. All of the properties have the same CSS names except hyphenated properties are camelcase.document.getElementById('elid').style.backgroundColor = "#BEEFEE";If you want to change the entire class you can use the class and className attributes, different browsers use different ones so set them both.document.getElementById('elid').setAttribute("class", "theclass");document.getElementById('elid').setAttribute("className", "theclass");
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...