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; } Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.