본문 바로가기

Web/Javascript

동적 스타일 시트 ㅣink 삽입

css 링크를 스크립트를 활용하여 동적으로 설정할 수 있다.


// 링크 객체 생성 
var cssNode = document.createElement("link");
cssNode.type = "text/css";
cssNode.rel = "stylesheet";
// 스타일 시트 파일 경로 설정
cssNode.href = "test.css";
cssNode.id = "dynamicLink";
// 생성 링크 head 태그에 삽입 
document.head.appendChild(cssNode);


'Web > Javascript' 카테고리의 다른 글