Recommended reading: JavaScript Harness Web-dom
JavaScript Harness Web-CSS and Dom
Segmenting HTML with DOM
Using JavaScript to control Web content is really like cooking. Just don't have to pack up the leftovers, but there is no way to enjoy the delicious fruit.
However, you will be able to complete the HTML elements of the Web content: More importantly, you will have the ability to replace the page components.
JavaScript allows you to manipulate the HTML code of a Web page at will, opening all sorts of interesting doors of opportunity, all because of standard objects: the existence of DOM
getElementById
HTML tags have an "id" attribute, which is unique to the label, and
can be obtained by the id attribute
<body>
<div id= "Div1" >
<div id= " Div2 ">
content
</div>
</div>
</body>
var scenedesc= document.getElementById ("Div2");
getElementById can access the value of the ID in the tag bracket through the element's ID attribute
getElementsByTagName
You can also use the tag name to get elements
<body>
<div id= "Div1" >
<div id= "Div2" >
<div id=
"Div3" > Content
</div>
</div>
</div>
</body>
var divs= document.getElementsByTagName ("div");
getElementsByTagName returns all div tags, the result is an array, and the results are listed in parentheses in the order of the tags in html the
tag name
var divs= document.getElementsByTagName ("div") [2];
Get a third div tag with an index
InnerHTML
The innerHTML feature provides access to all content stored in the element
through innerHTML access to the content stored within the element:
<div id= "Div1" >
<p id= "Story" > You are are standing</p> <strong>alone</strong> in the
Woods.
</div>
</body>
document.getElementById ("story"). InnerHTML;
The return content is: You are standing alone in the woods.
InnerHTML gets all the content and tags under the specified element
InnerHTML can also be used to set Web page content
document.getElementById ("story"). Innerhtml= "You are <strong>not</strong> alone! ";
innerHTML is used only to set labels that can contain text
About JavaScript Control Web page-Get the knowledge of the page elements to introduce so much, I hope to help you!