DOM--JS basic Knowledge (iv)

Source: Internet
Author: User

I. Three important components of JavaScript

(1) ECMAScript (European Association of Computer Manufacturers)

The specification of JS is developed

(2) DOM (Document Object model) Key Learning Objects

Methods and interfaces for handling Web page content

(3) BOM (Browser object model) has compatibility issues

Methods and interfaces for interacting with the browser

1. DOM definition

The specification for JS to manipulate HTML elements, such as the DOM tree

2. Node

The entire document is a document node

Each tag is an element node

The text in the label is a text node

The attribute in the tag is an attribute node

3. Methods of accessing nodes

getElementById ();

getElementsByTagName ();

Getelementsbyclassname (); There is a compatibility problem, so we need to encapsulate a method to get the class

4, encapsulate their own method of acquiring class class

Principle: In fact, it is to traverse all the tags in the document, from these tags to find the same class as your own class.

Compatibility issue: Is Getelementsbyclassname (), there is a compatibility issue, but we can still use in the Advanced browser

Code:

functiongetclass (classname) {//If the browser supports this method, we still don't waste his performance, try to use    if(document.getelementsbyclassname) {returndocument.getelementsbyclassname (classname); }    //If you cannot use    vararr = []; varDom = document.getElementsByTagName ("*");  for(vari = 0; i < dom.length; i++) {        if(Dom[i].classname = =classname)        {Arr.push (dom[i]); }    }    returnarr;}

  

DOM--JS basic Knowledge (iv)

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.