<style> #h:hover { background-color: green; } </style> <body> <div id='h'> HHHHH </div> <script type='text/javascript'> var f = document.getElementById('h'); f.onclick = function() { f.style.backgroundColor = 'red'; } </script> </body>