adam84 Posted June 18, 2009 Share Posted June 18, 2009 I am having trouble changing an elements css class. What I want is when the div element is clicked, i want to change to style sheet so that it has the border around it. Thanks //html <html> <head> <link rel="stylesheet" type="text/css" href="test.css" id="test"/> <script> function divClick(id){ document.getElementById(id).setAttribute("class", "test"); } </script> </head> </body> <br /><br /> <div name="myDiv" id="myDiv" onclick="javascript:divClick(this.id);">This is a test</div> </body> </html> //css .highlight{ border: .2em dotted #900; } #border { border-width: .2em; border-style: dotted; border-color: #900; } Link to comment https://forums.phpfreaks.com/topic/162809-change-css/ Share on other sites More sharing options...
xtopolis Posted June 19, 2009 Share Posted June 19, 2009 You are giving it a class of "test" which is not defined in the CSS you provided. Changing "test" to "highlight" works. Link to comment https://forums.phpfreaks.com/topic/162809-change-css/#findComment-859338 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.