HTML DOM
Through the HTML DOM, you can access all the elements of a JavaScript HTML document.
When a Web page is loaded, the browser creates a Document object model for the page.
The HTML DOM model is constructed as a tree of objects.
get node
GEtelementbyid: The only node that is taken through the ID.
Getelementsbyname (): By Name property
getElementsByTagName (): Signed by label
Getelementsbyclassname (): by class name
The following three getelements take the array format, cannot add the various attributes directly, but should remove each individual action of the array.
Example: Getelementsbyname ("Name1") [0].onclick=function
1. In JavaScript, document.write () can be used to write content directly to the HTML output stream.
Cases
<! DOCTYPE html>
2. If you want to change the content of the HTML element use document.getElementById (ID). innerhtml=New HTM
3. Change the properties of HTML elements using document.getElementById (ID). attribute=New Value
<! DOCTYPE html> html> <body> <script> document.getElementById ("image"). src= "Landscape.jpg"; </script> </body>
4. HTML DOM allows JavaScript to change the style of HTML elements.
document.getElementById (ID). style.property=New Style
1, view the attribute node, getattribute ("attribute name");
2. Set attribute node: SetAttribute ("Property name", "new property value")
DOM Event:
OnClick Click
The onload and OnUnload events are triggered when the user enters or leaves the page.
OnChange events are often combined with validation of input fields to use
The onmouseover and onmouseout events can be used to trigger a function when the user's mouse is moved above or out of an HTML element
OnMouseDown event is triggered when the mouse button is clicked
OnMouseUp event is triggered when the mouse button is released
When the onfocus gets focus
Basic use of JavaScript summary ②dom