Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created December 11, 2012 19:57
Show Gist options
  • Save tmcw/4261587 to your computer and use it in GitHub Desktop.
Save tmcw/4261587 to your computer and use it in GitHub Desktop.
Click Events, lol, wut
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
div {
margin:5px;
width:900px;
height:100px;
font:30px 'Comic Sans';
color:#fff;
background:magenta;
position:absolute;
}
#wut {
background:cyan;
}
</style>
</head>
<body>
<div id='wut'>wut</div>
<div id='lol'>lol</div>
<script>
// fully-featured jquery replacement mobile ready blah blah
function $(x) {
var d = (x[0] !== '.') ? document.getElementById(x) : document.getElementsByClassName(x.slice(1));
d.on = function(x, c) {
if (d.length) for (var i = 0; i < d.length; i++) d[i].addEventListener(x, c);
else d.addEventListener(x, c);
return d;
}
return d;
}
function say(e) { alert('clicked') }
$('lol').on('mousedown', function() {
$('wut').style.zIndex=2;
}).on('click', say);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment