Tuesday, 15 April 2014

events - JavaScript - Set onmouseover for multiple elements without using :hover -



events - JavaScript - Set onmouseover for multiple elements without using :hover -

is there way can not using :hover , not adding "onmouseover , onmouseout" in elements, effective way in script witch sets onmouseover , onmouseout input elements.

note: please seek javascript before trying jquery

<head> <title>123</title> <style> .button { color: red; } .button:hover { color: blue; } </style> </head> <body> <div> <input class="button" type="button" value="1"> <input class="button" type="button" value="2"> <input class="button" type="button" value="3"> </div> </body>

not recommend this, seek putting event handler mouseover on body element , utilize event.target / event.srcelement determine whether want handle event or not

document.body.addeventlistener("mouseover",function(e) { e = e || window.event; var targetelem = e.target || e.srcelement; // can utilize switch on nodename , handle event switch(targetelem.nodename) { case 'input': // break; } },false);

sample js fiddle (with background color change) http://jsfiddle.net/rcgx5/

javascript events hover

No comments:

Post a Comment