Javascript HTML DOM

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.