Napisałem funkcje, co chcę osiągnąć:
Pod każdym utworzonym odnośniku "a href" chcę podpiąć EventHanler onclick np żeby realizował mi funkcję test() po kliknięciu nań.
oto kod:
function createAhrefs(div_name) { var div = document.getElementById(div_name); div.style.width=200; div.style.height=200; div.style.backgroundColor="black"; div.style.color="white"; for(var iter = 1; iter <=js_counter; iter++) { /* tworzę dynamiczny odnośnik */ a=document.createElement("a"); a.setAttribute("href",iter); a.appendChild(document.createTextNode(iter)); a.style.color="green"; a.id=iter+"link"; div.appendChild(a); } } function test() { for(var iter = 1; iter <=js_counter; iter++) { var div = document.getElementById(iter+"link"); alert("YUPI !!! "+div); } }