hgmme@wa Posted January 16, 2008 Share Posted January 16, 2008 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 More sharing options...
justsomeguy Posted January 16, 2008 Share Posted January 16, 2008 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 More sharing options...
hgmme@wa Posted January 16, 2008 Author Share Posted January 16, 2008 document.getElementById('elid').setAttribute("class", "theclass");document.getElementById('elid').setAttribute("className", "theclass");Sweet, just what I needed. Thanks. Link to comment Share on other sites More sharing options...
aspnetguy Posted January 17, 2008 Share Posted January 17, 2008 doing the following works on IE, FF, and Opera document.getElementById('elid').className = 'theclass'; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.