프로그래밍/Web
[javascript] HTML DOM 생성 후 이벤트 추가
galad
2009. 12. 16. 12:34
var el = document.createElement("span"); el.setAttribute("title", key); el.setAttribute("class", "dpCatLabel"); //el.setAttribute("onclick", "alert('TEST');"); // DOESN'T WORK. onclick is not attribute. el.onclick=function(){alert("TEST");}; var txt = document.createTextNode(label); el.appendChild(txt); |
onclick 등은 이벤트라서 setAttribute로 붙일 수 없고,
el.onclick=function; 으로 붙이자.