[ACCEPTED]-How can I set a css ":hover" on a DOM created element in JavaScript?-dom

Accepted answer
Score: 13

You can dynamically create and manipulate 4 stylesheets. See here for some of the cross-browser 3 issues with this approach.

I've got a wrapper 2 function lying around which works around some of them; using 1 it, the code would read

document.createStyleSheet().addRule('#myDiv:hover', 'background:#000000;');
Score: 3

you may create element with predefined class:

.h:hover{color: #c00}

var elem = document.createElement('div');
elem.className = 'h'

0

More Related questions