JavaScript Document Object Usage (very important)

Source: Internet
Author: User

First, find the element

document.getElementById ("id"): Based on the ID to find a layer, up to find a

var A=document.getelementbyid ("id"): Place the found element in variable A;

Document.getelementbyname ("name"): Based on name, find out the array;

Document.getelementbytagname ("name"): Based on the name of the tag, find out the array;

Document.getelementbyclassname ("name"): According to ClassName, find out the array;

Ii. contents of operation

1, non-form elements

1), alert (a.innerhtml): Get the HTML content inside the a tag,

2), alert (a.innertext): Only get the text inside the A tag

2. Form elements

1), Var a=document.f1.t1; Gets the form form IDF1 input with ID t1

2), alert (t.value); Gets the value in input

3), alert (t.innerhtml): Gets the value of table cell <textarea> </textarea>

4), setting content: t.value= "content change";

5), attribute onclick= "return flase": Will not jump, the button will not be submitted

Third, attribute control

1), A.setattribute (property name, property value): Sets a property. Add or change all can;

2), A.getattribute ("Property name"): Gets the value of the property

3), A.removeattribute ("Property name"): Removes an attribute.

Four, Operation style

1), a.style. style = "": Manipulate this ID style property

2), a.classname= "ClassName in style sheet" to manipulate a batch of styles.

JavaScript Document Object Usage (very important)

Related Article

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.