흑염소처럼

js에서 html tag에 class name 추가 본문

JavaScript/기초 문법

js에서 html tag에 class name 추가

미니리틀타이니 2020. 7. 5. 14:58

한개의 클래스 추가

element.className = "class_test_name";

두 개이상의 클래스 추가

element.classList.add = "class_A"; 
element.classList.add = "class_B";

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

 

해당 에러 처리

var z = '<p>test satu dua tiga</p>'; // is a string Not node
document.body.appendChild(z);

string을 리턴받아 appendChild로 넣으니까 자꾸 에러가 남!

Node로 넣어줘야함

var z = document.createElement('p'); // is a node
z.innerHTML = 'test satu dua tiga';
document.body.appendChild(z);

참조 : https://stackoverflow.com/questions/27079598/error-failed-to-execute-appendchild-on-node-parameter-1-is-not-of-type-no

Comments