JavaScript DOM, javascriptdom

Source: Internet
Author: User

JavaScript DOM, javascriptdom
JavaScript DOM

 

I. Introduction

 

The relationship between JavaScript and DOM has been mentioned earlier:

DOM (document object model) is a set of methods to abstract and conceptual the document content, and provides APIs for manipulating browser content.

All operations performed by JavaScript on webpages are performed by DOM to change the content and method of browser rendering. DOM is the core content defined in the browser rather than the JavaScript language specification.

This article focuses on DOM.

 

Ii. DOM

 

D -- Document: DOM is automatically generated when a webpage is created and loaded into a web browser. Converts a webpage document into a document object.

O -- Object: Object. For example, the document object that converts a webpage document. Objects in JavaScript are divided into three types (as described in the previous article): user-defined object, nativeobject, and host object ).

M -- Model or Map: the representation of something.

 

Iii. Nodes

 

Elementnode: it is the DOM atom, corresponding to elements in the document, such as div, p, li, and other element nodes.

Textnode: it is always contained in element nodes.

Attributenode: used to describe elements in more detail.

 

Iv. CSS

 

Cascading StyleSheet: changes the document presentation form, has the inheritance feature, that is, the style added to an element also applies to all the elements contained in this element, but can be overwritten.

 

5. Common DOM Methods

 

1. Get element -- used for document object!

/** * Get element */// reture one elementvar element = document.getElementById('id');//reture an array.var elements = document.getElementsByTagName('tag');//reture an array.var elements = document.getElementsByClassName('class');

If getElementsByClassName does not work, you can implement it as follows:

 

function getElementsByClassName (node, className) {if (ndoe.getElementsByClassName) {return node.getElementsByClassName(className);} else {var result = new Array();var elems = node.getElementsByTagName('*');for (var i = elems.length - 1; i >= 0; i--) {if (elems[i].className.indexOf(className) != -1){result[i] = elems[i];}}return result;}}

2. Operation element attributes

 

/** * Attribute operation */document.getAttribute('attr');document.setAttribute('attr', value);

Vi. Supplement

There are only a few DOM methods, not DOM APIs, and many other methods are not listed.

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.