I need to find a by-change css:hover properties using JavaScript.
For example, suppose I has this HTML code:
<table> <tr> <td>Hover 1</td> <td>Hover 2</td> </tr></table>
And the following CSS code:
table td:hover {background:#ff0000;}
I would like-to-use JavaScript-the <td> hover properties to, say, background: #00ff00. Know I could access the style background property using JavaScript as:
document.getElementsByTagName("td").style.background="#00ff00";
But I don ' t know of a JavaScript equivalent for:hover. How does I change these <td> ' S:hover background using JavaScript?
|
Pseudo classes ( like:hover) never refer to a element, but to any element that satisfies the conditions of the stylesheet rule. You need toEdit the stylesheet rule, append a new rule, or add a new stylesheet that includes the new:hoverrule. |
VarCss= ' Table td:hover{padding:0px; border:0px; Color:rgb (48, 51, 54); " >;Style=Document.CreateElement(' Style ');If (Style.StyleSheet) {Style.StyleSheet.csstext = Css;} else {. Appendchild (document. Createtextnodecss}document. ( ' head ' 0 appendchild (style
Change:hover CSS properties with JavaScript