본문 바로가기

php/HTML

document.all 객체접근

document.all.id
document.all[id]
document.getElementById("id")


document.getElementById("id") 가 W3C가 표준으로 지정한 방식이고,
document.all은 표준화 하기 이전에 IE에서 사용하던 방식이다.
따라서 둘다 검사해주어야 ie예전버젼에 동작할 수 있겠다.

셋 모두로 객체접근을 할 수 있다. 


-- 참고 --  출처 : http://okjsp.pe.kr/bbs?act=VIEW&seq=51218&bbs=bbs4&keyfield=content&keyword=&pg=0
function getObject(objectId) { 
// checkW3C DOM, then MSIE 4, then NN 4. 
// 
if(document.getElementById && document.getElementById(objectId)) { 
return document.getElementById(objectId); 

else if (document.all && document.all(objectId)) { 
return document.all(objectId); 

else if (document.layers && document.layers[objectId]) { 
return document.layers[objectId]; 
} else { 
return false; 



즉, 다음처럼 하면 됩니다. 

getObject('sendbn').style.visibility="hidden"; 

getObject는 http://www.orient-express.com/js/layers.inc 에 있습니다. 

혹은 다음에 있는 'x library'를 쓰는 것도 좋은 방법입니다. http://www.cross-browser.com