Although some JavaScript frameworks such as jQuery, Prototype, and MooTools can improve our front-end development efficiency and solve browser compatibility problems, we still need to lay a solid foundation for javascript technology. This article will introduce JavaScript and the Document Object Model (DOM)... SyntaxHigh
Although some JavaScript frameworks such as jQuery, Prototype, and MooTools can improve our front-end development efficiency and solve browser compatibility problems, we still need to lay a solid foundation for javascript technology. This article introduces the nature of JavaScript and the Document Object Model (DOM.
JavsScript is a dynamic, loosely typed, and prototype programming language that can be used in various environments. In addition to being a popular Web Client programming language, it can also be used by IDE plug-ins, PDF files, or other platforms or even more abstract concepts.
JavaScript is a language based on ECMAScript standard (ECMA-262) created by Brendan Eich from Netscape. He was initially named LiveScript but later changed to JavaScript, which is one of the reasons why many people will confuse it with java. The following is a detailed description of some of its features:
◆ Dynamic programming languages are executed at runtime; they are not compiled. For this reason, JavaScript is sometimes considered a scripting language rather than a real programming language (obviously a misunderstanding ).
◆ Loose type languages do not require strong type systems. If you declare variables using C or Java programming (different from JavaScript), you will understand that the declaration must be similar to 'int' (integer ). The difference in JavaScript is that you don't need to specify its type.
◆ In JavaScript, we use prototype to achieve similar inheritance effects. JavaScript does not support classes.
◆ JavaScript is also a functional language, and its processing function is a priority object. It is based on the concept of lambda.
Understanding the above concepts is not very relevant to learning JavaScript. It just gives you a preliminary and correct understanding of JavaScript and the essential differences between JavaScript and other programming languages.
Document Object Model
Document Object Model (DOM) is an interface for intercommunication between website content and JavaScript. When JavaScript becomes the most common language, JavaScript and DOM are usually considered as independent entities. The DOM interface is used to access, traverse, and control HTML and XML documents.
Below are some important knowledge about DOM:
◆ The Window object is a global object. You only need to use "window" to access it. The Window object contains all your JavaScript code to be executed. Just as all objects contain attributes and methods.
◆ Attributes are variables stored in objects. All the variables created on the web page will become the properties of the window object.
◆ The method is the function stored in the object. When all functions are stored in window objects, you can use 'Methods 'to reference them.
◆ DOM creates a hierarchy with nodes relative to the Web document structure. DOM nodes have many different types, the most important of which are 'element', 'text', and 'document.
◆ The 'element' node indicates the elements on the page. Therefore, if you have a section Element ('
'), Then you can access it through the DOM node.
◆ The 'text' node indicates all Text in the page (in the element), so if there is some Text content in the section of the page, you can access it through the DOM node.
◆ The 'document' node indicates the entire Document. (It is the root node of the DOM tree)
◆ Note that the element attribute is the DOM Node itself.
◆ The execution of DOM standards varies with different Layout engines. For example, the FireFox browser that uses the Gecko Layout Engine can perform well (but it is not exactly the same as the W3C Specification ), however, Internet Explorer using the Trident engine is well known for its many bugs and incomplete DOM Standard execution. This is a major pain point in the front-end development field.
JavaScriptScript element in the webpage
When you want to use JavaScript on your website, you need to include them in the script element:
JavaScript!