JavaScript / October 1, 2010

First Post: JS Closure Example

While creating 10 <a> elements, each link pointing at a different id number. In that case, this example makes sense. [js autolinks=”false”] for (var i = 0; i < 10; i++) { var a = document.getElementById(‘a’); a.onclick = function(e) { location.href = ‘http://www.example.com/?id=’ + i; }; document.body.appendChild(a); } [/js] However, the creation of the anonymous

Read More