n00b Saibot wrote:simple
will do it.
That nearly works, except the function gets called. If I do:
Code: Select all
ea.onclick = function() { myFunction; }
It works ok. I've a feeling nasty something like that causes a memory leak in IE though.
Next question, how can I pass parameters to myFunction? I need to generate these links in a loop, and call myFunction(x);, where x is the counter. So each link is to the same function but with a different number. It seems to make them all call the function with the same number if I use:
Code: Select all
for (var h=0; h <= 5; h++) {
ea = document.createElement("a");
ea.href = '#';
ea.onclick = function() { myFunction(h); }
ea.appendChild(document.createTextNode(h+1));
el = document.createElement("li");
el.appendChild(ea);
ul.appendChild(el);
}
They all call myFunction(5).