Hi in my CSS I have something like: #mydiv:hover { background: blue; } How do I access this in my Javascript so I can change this inside my function?
perhaps something like ... <div id="mydiv">foo</div> <script> document.getElementById("mydiv").onmouseover = function() { this.style.backgroundColor = "blue"; } </script> Code (markup):
Thanks for the reply, Is there no way to access the :hover function inside the JS? I have got it working by changing the class name on click. This leads me to 2 final questions: Is it possible to get element by class rather than get element by ID? Is is possible to change an ID name, currently I am changing class name via: myvar.className="newname";
yes, you can get an element by class. there is a new function that will get included in future browser releases: http://developer.mozilla.org/en/DOM/document.getElementsByClassName in the meanwhile you can: getElementsByTagName("div") ... then iterate through results and check className property of the objects... get a framework (check my blog on selectors). good luck