1: Changing the content of HTML elements
Use the InnerHTML method: document.getElementById (ID). innerhtml=new HTML such as: document.getElementById ("P1"). innerhtml= "New text!"; 2: Change HTML element properties using document.getElementById (ID). Attribute=new value such as: document.getElementById ("image"). src= " Landscape.jpg "; 3: Change HTML style using: document.getElementById (
ID). style.property=
New Style
such as:document.getElementById ("P2"). style.color= "Blue"; 4: Reacting to events example of an HTML event:-When the user clicks the mouse-when the page loads-when the picture is loaded-when the mouse
MovingTo an element-when the input field is changed-when the HTML form is submitted-when the user triggers the button, such as: when clicking on the element, execute the JS code, Nclick=javascript
onclick="this.innerHTML=‘谢谢!‘"> Click the text <script>document.getElementById ("mybtn"). Onclick=function () {displaydate ()};function displaydate () {document.getElementById ("Demo"). Innerhtml=date (); }</script>Reference: HTML DOM Event Objecthttp://www.w3school.com.cn/jsref/dom_obj_event.asp 5: Create a new HTML elementTo add a new element to the HTML DOM, you must first create the element (the element node), and then append the element to an existing element.use Element.appendchild (para); 6: Delete an existing HTML elementParent.removechild (child);
Javascript HTML DOM