2009. 9. 21.

DOM 메소드, 프로퍼티 등

Methode (DOM 1.0 model)



getElementById
document.getElementById("element")
$("element") by prototype.js


getElementsByTagName
document.getElementsByTagName("select")
document.getElementsByTagName("a")
document.getElementsByTagName("p")
document.getElementsByTagName("div")


getAttribute
 element.getAttribute("title")
 element.getAttribute("value")


setAttribute
element.setAttribute("value","the value");
element.value = "the value";
element.setAttribute("src","/images/defaultimg.gif");
element.src = "/images/defaultimg.gif";


createElement
document.createElement(nodename);
document.createElement("p");
document.createElement("img");
document.createElement("div");
var para =  document.createElement("p");
 

createTextNode
document.createTextNode("Hello World")
var txt = document.createTextNode("Hello World")


appendChild
element.appendChild(txt);


insertBefore
parentNode.insertBefore(newElement, targetElement)
var Elem = document.getElementById("elementname")
Elem.parentNode.insertBefore(newElem, Elem)
새로운 엘리먼트 newElem 을 Elem 앞에 추가함
 




Property

parentNode
var parent = targetElement.parentNode
childNode
var child = targetElement.childNode

nodeName
nodeType
nodeValue

firstChild
element.firstChild
lastChild
element.lastChild

nextSibling






참고할 만한 만든함수


addLoadEvent()

function addLoadEvent(func){
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
     window.onload = func;
  }else {
     window.onload = function(){
oldonload();
        func();
     }
  }
}

insertNext()



기억할만한 표현기법

var 변수 = 만족시키는조건 ? 그럼이거 : 아니면이거;
var test = elem.getAttribute("title") ? elem.getAttribute("title") : "No Elem" ;




가급적 피해야 할... 구형메소드들...

document.write
 - document.write("some text...");

element.innerHTML
 - element.innerHTML = "some text...";
 - alert(element.innerHTML);

0 개의 댓글:

Archive

prof

With you not around it’s a little bit more than I can stand. Don’t tell me I ran out of time If it takes the rest of my life.