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)