관리 메뉴

드럼치는 프로그래머

[JavaScript] Add onClick event to document.createElement(“th”) 본문

★─Programing/☆─WebProgram

[JavaScript] Add onClick event to document.createElement(“th”)

드럼치는한동이 2016. 7. 28. 09:19
var newTH = document.createElement('th');
newTH.innerHTML = 'Hello, World!';
newTH.onclick = function () {
    this.parentElement.removeChild(this);
};

var table = document.getElementById('content');
table.appendChild(newTH);


Working example: http://jsfiddle.net/23tBM/


You can also just hide with this.style.display = 'none'.


[출처] http://stackoverflow.com/questions/11017509/add-onclick-event-to-document-createelementth


Comments