DOM document. document, . DOM document.
DOM:
document.documentElement . HTML-, <html>;
document.body <body>, ( );
document.getElementsByTagName() ;
document.getElementById(ID) id;
document.getElementByName() name.
, , . :
1. , childNodes[].
2. firstChild lastChild null, .
3. parentNode .
4. previousSibling nextSibling .
DOM
, DOM:
1. tagName - , ;
2. style - . CSS;
3. innerHTML - HTML- , , , ;
4. className - , html- class;
5. onclick, onkeypress, onfocus . - - .
body , , HTML- . , ( HTML) innerHTML.
<html>
<head>
<script>
functiongo(){
varS="";
for(vari=0;i<document.body.childNodes.length;i++){
varchild=document.body.childNodes[i];
//alert(child.tagName);
S=S+i+"-"+child.tagName+"="+child.innerHTML+" ";
}
alert(S);
}
</script>
</head>
<body>
<divid="dataKeeper"></div>
<ul>
<li> 1</li>
<li> 2</li>
</ul>
<divid="footer"> </div>
<inputtype="button"onclick="go()"value="Go"/>
</body>
</html>
DOM
HTML, DOM- .
div id, class alpha:
<divid="MyElement"class="big"alpha="omega"></div>
, . :
|
|
setAttribute(name, value) ;
getAttribute(name) ;
hasAttribute(name) , ;
removeAttribute(name) .
.
. , , . . class className, .. class javascript.
id:
<html>
<head>
<script>
functiongo(){
document.body.setAttribute('id','NewId');//
alert(document.body.id)//
}
</script>
</head>
<body>
<inputtype="button"onclick="go()"value="Go"/>
</body>
</html>