LinkedNestBlog

document.setAttribute의 IE7 오류

by jinwon

===========================================================================
document.setAttribute의 IE7 오류
===========================================================================
1. class
: document.setAttribute로 class 설정할 때 동작 안하는 이유
---------------------------------------------------------------------------------------------
참고 URL: http://jandcgroup.com/2010/01/26/javascript-class-and-classname-with-ie8-and-ie7/
---------------------------------------------------------------------------------------------
오류 내용: 자바스크립트 메서드에서 document.setAttribute로 설정한 class가 적용되지 않는 현상 발생.
이유: IE 6, IE 7은 class 대신 className을 인식한다고 한다.
해결 내용: 조건에 따라 class로 설정할지, className으로 설정할지를 구분한다.

2. name
3. style
: name과 style이 설정 안되는 이유
----------------------------------------
아직 이유는 모름
----------------------------------------
2.와 3.에 대해서는 아래와 같이 조치한다.
if($.browser.msie && $.browser.version < 8.0){
 input = document.createElement("<input type='text' name='articleName' style='width:95%;'>");
}else{
 input = document.createElement("input");
}  
input.setAttribute("type", "text");
input.setAttribute(document.all ? "className" : "class","input01");
input.setAttribute("style","width:95%;");
input.setAttribute("id","articleName"+(articleLength+1));
input.setAttribute("name","articleName");