Through the HTML DOM, JavaScript can access and modify each element in an HTML document
Modify the text elements
document.getElementById ( "p1") innerHTML = " new text!";. // update the id is the text content of the element node p1
Modify the style elements
document.getElementById("p2").style.color="blue"; document.getElementById("p2").style.fontFamily="Arial"; document.getElementById("p2").style.fontSize="larger";
Modifications required by responding to events
HTML DOM allowed to execute corresponding code when the event occurs, the event comprising:
in clicking on the element, such as response onclick event
page is loaded, such as direct writing <scripts> </ scripts> the
change in the input field, such as onblur event response
<Script> function OnClickEnvent () { document.body.style.backgroundColor = "Lavender"; // change the body color document.getElementById ( "p1") the innerHTML = "the Hello World!";. // update id is the p1 element text } </ Script> <the p-the above mentioned id = "p1"> the Hello! </ the p-> <the INPUT of the type = "the Button" onclick = "OnClickEnvent ()" value = "click event" />