Window.document Object

Source: Internet
Author: User

First,Window.document object

1. Find element:

Docunment.getelementbyid ("id"); Search by ID, up to one;
var a =docunment.getelementbyid ("id"); The found element is placed in a variable;
Docunment.getelementsbyname ("name"); Search by name, find the array;
Docunment.getelementsbytagname ("name"); Based on the name of the tag, find out the array;
Docunment.getelementsbyclassname ("name") according to ClassName, find out the array;

2. Get content

(1) Non-form elements:

a.innerhtml, the HTML code and text in the tag are all retrieved, all the contents of the tag.

A.innertext; take only the words inside

a.outerhtml; including the contents of the label itself

(2) Form elements

var t = document.f1.t1; The form ID of the form is F1 with ID T1 input;
var t = document.getElementById ("id"); Get directly with ID.

knowledge Point:<a href= "http://www.baidu.com" onclick = "return false"> turn to Baidu </a>; add return Flase will not jump, the default is return true will jump. The button is the same, if the button is set to return flase will not commit, this can be used to control the commit jump.

3 Action Properties

First, the element is found with the ID of the element, stored in a variable: var a = document.getElementById ("id");

You can then manipulate the attributes of the element:

A.setattribute ("attribute name", "attribute value"); Set a property, add or change all can;

A.getattribute ("attribute name"); Gets the value of the property;

A.removeattribute ("attribute name"); Remove an attribute.

Window.document Object

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.