JSFiddle - React, Tailwind, and code Playground

by gryzzly

HTML

<div id="test"></div>

CSS

#test {
    margin:15px;
    width:300px;
    height:400px;
    background:#bada55;
}

JavaScript

// create a closure, so our vars don't pollute global scope
(function() {
    // element 
    // if you want, you can just attach the event listener
    // directly to the `document`
    var el = document.getElementById('test'),
        goAway = function() {
            window.location.href = 'http://google.com';
        };
            
    if ( el.addEventListener ) {
      el.addEventListener('mousemove', goAway, false); 
    } else if ( el.attachEvent ){
      el.attachEvent('onmousemove', goAway);
    }
    
})();