JavaScript DOM 1

function print(str) {    
   document.write("<strong style='color:green;'>"+str+"</strong>");    
}    
function println(str){    
    if(str){    
        document.write("<strong style='color:green;'>"+str+"</strong><br/>");    
    }    
    else{    
        document.write("<br/>");    
    }    
}   

println(document.documentElement);//<html> root
println(document.body);//<body>
println(document.doctype);//<!DOCTYPE html>

//output node type info
for(var type in Node){
    println(type);
    println(Node[type]);
}

println(document.childNodes[0].nodeName);
println(document.firstChild.nodeName);

println(document.title);
println(document.URL);
println(document.domain);

println(document.anchors);//<a>
println(document.forms);//<form>
println(document.images);//<img>
println(document.links)//<link>

//document.createDocumentFragment();//like a group,but not occupy page resources

//css selector
println(document.querySelector("body"));//return first child
println(document.querySelectorAll("body"));//return all child list

println(document.firstElementChild);
println(document.lastElementChild);
println(document.childElementCount);
println(document.nextElementSibling);
println(document.previousElementSibling);

println(document.classList);

println(document.activeElement);

println(document.readyState);//loading and complete
println(document.head);

println(document.dataset);

println(document.outerHTML);//contains tag self and its children

println(document.children);
println(document.documentMode);
println(document.contains(document.body));

// document.body.scrollByLines(10);
// document.body.scrollByPages(1);


[object HTMLHtmlElement]
[object HTMLBodyElement]
[object DocumentType]
ELEMENT_NODE
1
ATTRIBUTE_NODE
2
TEXT_NODE
3
CDATA_SECTION_NODE
4
ENTITY_REFERENCE_NODE
5
ENTITY_NODE
6
PROCESSING_INSTRUCTION_NODE
7
COMMENT_NODE
8
DOCUMENT_NODE
9
DOCUMENT_TYPE_NODE
10
DOCUMENT_FRAGMENT_NODE
11
NOTATION_NODE
12
DOCUMENT_POSITION_DISCONNECTED
1
DOCUMENT_POSITION_PRECEDING
2
DOCUMENT_POSITION_FOLLOWING
4
DOCUMENT_POSITION_CONTAINS
8
DOCUMENT_POSITION_CONTAINED_BY
16
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
32
html
html
DOM Studying
file:///D:/programming/www/demo6.html

[object HTMLCollection]
[object HTMLCollection]
[object HTMLCollection]
[object HTMLCollection]
[object HTMLBodyElement]
[object NodeList]
[object HTMLHtmlElement]
[object HTMLHtmlElement]
1



[object HTMLBodyElement]
loading
[object HTMLHeadElement]


[object HTMLCollection]

true


阅读更多
版权声明:The beautiful thing about learning is nobody can take it away from you. https://blog.csdn.net/xiuye2015/article/details/80466138
个人分类: JavaScript
上一篇JavaScript OOP 10
下一篇JavaScript DOM Canvas 2
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭