getElementaryByTagName() 함수를 사용하면 HTML DOM 에서 특정 tag에 대해서 받아올수 있다.
그리고 이 함수는 NodeList 를 돌려준다.
NodeList는 Node의 배열도 아니고 먼가 희한한 방법으로 접근을 한다.
x = document.getElementsByTagName("td");
document.write(x.item(i).nodeName);
이렇게 하면 TD 태그로 받아왔으므로, nodeName은 TD가 리턴된다.
한글2010 에서 작성한 표는 <P> 태그로 쌓여 있는데 그런 이유로 NULL 값이 나오는것으로 생각된다.
|
- document.getElementById("ol1")
- document.getElementsById("li1").parentNode
- document.getElementsByTagName("ol").item(0)
- document.getElementsByTagName("li").item(0).parentNode
- document.getElementsByTagName("li").item(1).parentNode
- document.getElementsByTagName("l1").item(2).parentNode
- document.getElementsByTagName("span").item(2).parentNode.parentNode
- document.getElementsByTagName("body").item(0).childNodes.item(0)
- document.body.childNodes.item(0)
[링크 : http://www.pageresource.com/dhtml/ryan/part4-2.html]
|
interface Node {
// NodeType
const unsigned short ELEMENT_NODE = 1;
const unsigned short ATTRIBUTE_NODE = 2;
const unsigned short TEXT_NODE = 3;
const unsigned short CDATA_SECTION_NODE = 4;
const unsigned short ENTITY_REFERENCE_NODE = 5;
const unsigned short ENTITY_NODE = 6;
const unsigned short PROCESSING_INSTRUCTION_NODE = 7;
const unsigned short COMMENT_NODE = 8;
const unsigned short DOCUMENT_NODE = 9;
const unsigned short DOCUMENT_TYPE_NODE = 10;
const unsigned short DOCUMENT_FRAGMENT_NODE = 11;
const unsigned short NOTATION_NODE = 12;
readonly attribute DOMString nodeName;
attribute DOMString nodeValue;
// raises(DOMException) on setting // raises(DOMException) on retrieval
readonly attribute unsigned short nodeType;
readonly attribute Node parentNode;
readonly attribute NodeList childNodes;
readonly attribute Node firstChild;
readonly attribute Node lastChild;
readonly attribute Node previousSibling;
readonly attribute Node nextSibling;
readonly attribute NamedNodeMap attributes;
// Modified in DOM Level 2:
readonly attribute Document ownerDocument;
Node insertBefore(in Node newChild,
in Node refChild)
raises(DOMException);
Node replaceChild(in Node newChild,
in Node oldChild)
raises(DOMException);
Node removeChild(in Node oldChild)
raises(DOMException);
Node appendChild(in Node newChild)
raises(DOMException);
boolean hasChildNodes();
Node cloneNode(in boolean deep);
// Modified in DOM Level 2:
void normalize();
// Introduced in DOM Level 2:
boolean isSupported(in DOMString feature,
in DOMString version);
// Introduced in DOM Level 2:
readonly attribute DOMString namespaceURI;
// Introduced in DOM Level 2:
attribute DOMString prefix;
// raises(DOMException) on setting
// Introduced in DOM Level 2:
readonly attribute DOMString localName;
// Introduced in DOM Level 2:
boolean hasAttributes();
};
[링크 : http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247]
|
interface Element : Node {
readonly attribute DOMString tagName;
DOMString getAttribute(in DOMString name);
void setAttribute(in DOMString name,
in DOMString value)
raises(DOMException);
void removeAttribute(in DOMString name)
raises(DOMException);
Attr getAttributeNode(in DOMString name);
Attr setAttributeNode(in Attr newAttr)
raises(DOMException);
Attr removeAttributeNode(in Attr oldAttr)
raises(DOMException);
NodeList getElementsByTagName(in DOMString name);
// Introduced in DOM Level 2:
DOMString getAttributeNS(in DOMString namespaceURI,
in DOMString localName);
// Introduced in DOM Level 2:
void setAttributeNS(in DOMString namespaceURI,
in DOMString qualifiedName,
in DOMString value)
raises(DOMException);
// Introduced in DOM Level 2:
void removeAttributeNS(in DOMString namespaceURI,
in DOMString localName)
raises(DOMException);
// Introduced in DOM Level 2:
Attr getAttributeNodeNS(in DOMString namespaceURI,
in DOMString localName);
// Introduced in DOM Level 2:
Attr setAttributeNodeNS(in Attr newAttr)
raises(DOMException);
// Introduced in DOM Level 2:
NodeList getElementsByTagNameNS(in DOMString namespaceURI,
in DOMString localName);
// Introduced in DOM Level 2:
boolean hasAttribute(in DOMString name);
// Introduced in DOM Level 2:
boolean hasAttributeNS(in DOMString namespaceURI,
in DOMString localName);
};
[링크 : http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-745549614]
|