(1) Reading and writing methods
Document.open () //For new and open a document Document.close () //uneasy than the open method of the newly created document document.write () // Used to write content to the current document Document.writein () //used to write to the current document, trailing add line breaks.
(2) Finding nodes
Document.queryselector (selectors)//accepts a CSS selector as a parameter, returning the first element node that matches the selector. Document.queryselectorall (selectors)//accepts a CSS selector as a parameter, returning all element nodes that match the selector. document.getElementsByTagName (tagName)//Returns all elements of the specified HTML tag document.getelementsbyclassname (className)// Returns an element that includes all class names that match the specified criteria Document.getelementsbyname (name)//To select an HTML element that has the name attribute (for example<form>、<Radio>、<img>、<Frame>、<Embed>And<Object>document.getElementById (ID)//Returns the element node that matches the specified ID attribute. Document.elementfrompoint (x, y)//Returns the element child node at the top of the page's specified position.
1.document.queryselector (selectors)//accepts a CSS selector as a parameter, returning the first element node that matches the selector.
Document.queryselectorall (selectors)//accepts a CSS selector as a parameter, returning all element nodes that match the selector.
<DivID= "text"> <DivID= "Test1">Test 1</Div> <DivID= "All"class= "All"> <I>Dream Dragon 1</I> <Pclass= "box"> <emclass= "span">Dream Dragon 2</em> </P> <Iclass= "span">Dream Dragon 3</I> <Pclass= "box"> <em>Dream Dragon 4</em> </P> </Div> </Div><Buttononclick= "myFunction ()">Point Me</Button><Scripttype= "Text/javascript"> functionmyFunction () {//gets the text content of the element with the class name Test1 vartext=document.getElementById ("text"). Queryselector ("#test1"); alert (text.textcontent); //gets all <i> elements of <div> in the class named All, similar to getElementsByTagName ("I") varI=document.getElementById (" All"). Queryselectorall ("I"); //alert (i[1].textcontent); //get all elements with a class name of span varspan=Document.queryselectorall (". Span"); //get all <em> elements in all <p> tags varem=Document.queryselectorall ("p em"); }</Script>
2.document.elementfrompoint (x, y)//Returns the element child node at the top of the page's specified position.
<p> User name View code file (online)</p>
<button id= "btn"> Coordinates (100,100) will change color.</Button><Script>document.getElementById ("btn"). onclick= function() {Document.elementfrompoint ( -, -). Style.color= "#cd0000"; };</Script>
The effect is as follows:
JavaScript Dom action method (4)--document node method