Skip to content

Instantly share code, notes, and snippets.

/gist:1718650

Created Feb 1, 2012
Embed
What would you like to do?
<html>
<head>
<style>
.target {
background: green;
border: 20px solid blue;
border-style: solid;
padding: 2em;
}
li {
background: #F00;
border: 0px solid black;
padding: 1em;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
}
</style>
<script>
function handleClick ( event ) {
if(this.lastNode) {
this.lastNode.className = "";
if (event.target.id == "item-1")
return;
}
var target = event.target;
switch(true) {
case (target.nodeType === 3):
// fix safari bug
target = target.parentNode;
break;
case (target.nodeName === "A"):
// goto LI
target = target.parentNode;
break;
}
this.lastNode = target;
target.className = "target";
}
document.addEventListener('click', handleClick, false);
</script>
</head>
<body>
<ul class="toggle">
<li id="item-1">Item 1</li>
<li id="item-2">Item 2</li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.