/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var elems = document.getElementsByTagName( 'a' ); for ( var i = 0; i < elems.length; i++ ) { (function( lockedInIndex ){ elems[ i ].addEventListener( 'click', function(e){ e.preventDefault(); alert( 'I am link #' + lockedInIndex ); }, 'false' ); })( i ); }
URL: http://benalman.com/news/2010/11/immediately-invoked-function-expression/