Dom Programming for JavaScript

Source: Internet
Author: User

DOM (Document Object model), language independent, is used to manipulate XML (in the Web) and HTML (in the browser) of the application interface of the document. The more times you access the DOM, the slower it is and the higher the cost.

InnerHTML Properties: Ducument.getelementbyid (' here '). InnerHTML ()

Categorization malleability Dom method: Ducument.createelement (), ducument. createTextNode ()

Node clone: Ducument.clonenode ()

Get collection: Ducument.getelementbyname ()

Ducument.getelementbyclassname ()

Ducument.getelementbytagname ()

This collection object is a list of similar arrays, without the push and slice methods of the array, but provides the length property in the array, using local variables when accessing the collection elements

All IMG elements in the page: ducument.images

All elements of a page: Ducument.links

All form elements on the page: ducument.forms

All fields of the first form on the page: ducument.forms[0].elements

Gets the first element: Ducument.getelementbyid (' div '). FirstChild

Get adjacent elements: Ducument.getelementbyid (' div '). firstchild.nextsibling

Gets the collection of elements: Ducument.getelementbyid (' div '). childNodes

API only returns ELEMENT nodes: child instead of childNodes

Childelementcount instead of Childnodes.length

Firstelementchild instead of FirstChild

Lastelementchild instead of LastChild

Nextelementchild instead of nextSibling

Previouselementsibling instead of previoussibling

Selector API:ducument.querySelectorAll (' #menu a ') <=> Ducument.getelementbyid (' menu '). Getelementbytagname (' a ')

Class is warning and notice elements: Ducument.queryselectorall (' div.warning, Div.notice ')

<=> var errs=[];

DIVs = doucument.getelementsbytagname (' div ');

ClassName = ";

for (var i=0; len = divs.length; i<len; i++) {

ClassName = Divs[i].classname;

if (className = = ' notice ' | | className = = ' Warning ') {

Errs.push (Divs[i]);

}

}

Dom Programming for JavaScript

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.