Basic use of JavaScript summary ②dom

Source: Internet
Author: User

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

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.