Skip to content

Instantly share code, notes, and snippets.

@meeech
Created January 20, 2011 17:46
Show Gist options
  • Save meeech/788257 to your computer and use it in GitHub Desktop.
Save meeech/788257 to your computer and use it in GitHub Desktop.
<html>
<body>
<ul>
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
</ul>
</body>
<script type="text/javascript">
// is it cheating to just adding a custom property?
els = document.getElementsByTagName('li');
for(i=0; i < els.length; i++){
els[i].position = i+1;
els[i].addEventListener('click', function(){alert(this.position);});
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment