JavaScript advanced programming DOM study notes_javascript skills
Chapter 10 DOM
DOM is an API for XML and HTML documents: it specifies the attributes and methods for text node manipulation, and the specific implementation is implemented by the respective browsers.
1. Node hierarchy
1) Document node: document, the root node of each document.
2) Document element: The element is the outermost element of the document and the first child node of the document node.
3) Node type:
①Node is the base type of various node types in the DOM, sharing the same basic properties and methods.
□ Node.Element_NODE(1);
□ Node.ATTRIBUTE_NODE(2);
□ Node.TEXT_NODE(3);
□ Node.CDATA_SECTION_NODE(4);
□ Node. ENTITY_REFERENCE_NODE(5);
□ Node.ENTITY_NODE(6);
□ Node.PROCESSING_INSTRUCTION_NODE(7);
□ Node.COMMENT_NODE(8);
□ Node.DOCUMENT_NODE(9);
□ Node.DOCUMENT_TYPE_NODE(10);
□ Node.DOCUMENT_FRAGMENT_NODE(11);
□ Node.NOTATION_NODE(12);
The nodeType attribute of each node returns one of the above types, which is a constant .
The node type can be obtained by comparing the nodeType attribute with the numeric value.
②nodeName and nodeVlue attributes.
③The child node information of each node is stored in the childNodes attribute, and a NodeList object is stored in the childNodes attribute.
□ NodeList object, an array-like object, has a length attribute, but is not an instance of Array.
□ To access the nodes in the NodeList, you can use square brackets or use the item() method.
var firstChild = someNode.ChildNodes[0];
var secondChild = someNode.ChildNodes.item(1);
var count = someNode.childNodes.length;
□ Convert NodeList to array object .
function convertToArray(nodes){
var array = null;
try{
array = Array.prototype.slice.call(nodes,0); //Non-IE
}catch( ex){
array = new Array();
for(var i = 0,len = nodes.length; i array.push(nodes[i]);
}
}
return array;
}
④parentName attribute: points to the parent node in the document tree.
⑤previousSibling attribute and nextSibling attribute: previous/next sibling node.
⑥firstChild attribute and lastChild attribute: previous/next child node.
⑦hasChildNodes() method: Returns true if it contains child nodes, otherwise it returns false.
⑧appendChild() method: Add a child node to the end of the childNodes list and return the newly added node.
⑨insertBefore() method: two parameters: the node to be inserted and the node used as a reference. Return the newly added node.
⑩replaceChild() method: two parameters: the node to be inserted and the node to be replaced. Return the newly added node.
⑾removeChild() method: remove node.
⑿cloneNode() method: accepts a Boolean value. true means deep copy, copying nodes and sub-nodes. false means shallow copy, only copying the own node.
⒀nomalize() method: Process text nodes in the document tree.
4) Document type (for document objects)
①Document type represents a document, which is an instance of the HTMLDocument type and represents the entire HTML page. The document object is a property of the window object and can be accessed as a global object.
②documentElement attribute; this attribute always points to the element in the HTML page.
③body attribute; points directly to the
④doctype attribute: Access , which is supported by different browsers. Of limited use.
⑤title attribute: The text of the title can be obtained and set.
⑥URL attribute: URL in the address bar.
⑦domain attribute: The domain name of the page (can be set, with restrictions)
⑧referrer attribute: Save the URL of the page linked to the current page
⑨getElementById() method: Pass in the ID of the element and return the element node.
⑩getElementsByTagName() method: Pass in the element name and return NodeList.
□ Returns an HTMLCollection object in HTML, similar to NodeList.
□ Access the HTMLCollection object: square bracket syntax, item() method, namedItem() method. The HTMLCollection object can also obtain the items in the collection through the name attribute of the element.
⑾getElementsByName() method: Returns all elements with the given name attribute.
⑿Special collections, these collections are HTMLCollection objects.
□ document.anchors: Contains all elements with the name attribute in the document.
□ document.applets: Contains all

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP study notes: Overview of data structures and algorithms: Data structures and algorithms are two very important concepts in computer science. They are the key to solving problems and optimizing code performance. In PHP programming, we often need to use various data structures to store and operate data, and we also need to use algorithms to implement various functions. This article will introduce some commonly used data structures and algorithms, and provide corresponding PHP code examples. 1. Linear structure array (Array) Array is one of the most commonly used data structures and can be used to store ordered data.

DOM is a document object model and an interface for HTML programming. Elements in the page are manipulated through DOM. The DOM is an in-memory object representation of an HTML document, and it provides a way to interact with web pages using JavaScript. The DOM is a hierarchy (or tree) of nodes with the document node as the root.

Vue3ref binding DOM or component failure reason analysis scenario description In Vue3, it is often used to use ref to bind components or DOM elements. Many times, ref is clearly used to bind related components, but ref binding often fails. Examples of ref binding failure situations The vast majority of cases where ref binding fails is that when the ref is bound to the component, the component has not yet been rendered, so the binding fails. Or the component is not rendered at the beginning and the ref is not bound. When the component starts to render, the ref also starts to be bound, but the binding between ref and the component is not completed. At this time, problems will occur when using component-related methods. The component bound to ref uses v-if, or its parent component uses v-if to cause the page to

1. Native js gets the DOM node: document.querySelector (selector) document.getElementById (id selector) document.getElementsByClassName (class selector).... 2. Get the instance object of the current component in vue2: because each vue Each component instance contains a $refs object, which stores references to the corresponding DOM elements or components. So by default, the component's $refs point to an empty object. You can first add ref="name" to the component, and then pass this.$refs.

In web development, DOM (DocumentObjectModel) is a very important concept. It allows developers to easily modify and operate the HTML or XML document of a web page, such as adding, deleting, modifying elements, etc. The built-in DOM operation library in PHP also provides developers with rich functions. This article will introduce the DOM operation guide in PHP, hoping to help everyone. The basic concept of DOM DOM is a cross-platform, language-independent API that can

There are 5 DOM objects including "document", "element", "Node", "Event" and "Window"; 2. "window", "navigator", "location" and "history" and "screen" and other 5 BOM objects.

BOM and DOM are different in terms of role and function, relationship with JavaScript, interdependence, compatibility of different browsers, and security considerations. Detailed introduction: 1. Role and function. The main function of BOM is to operate the browser window. It provides direct access and control of the browser window. The main function of DOM is to convert the web document into an object tree, allowing developers to Use this object tree to obtain and modify the elements and content of the web page; 2. Relationship with JavaScript, etc.

dom内置对象有:1、document;2、window;3、navigator;4、location;5、history;6、screen;7、document.documentElement;8、document.body;9、document.head;10、document.title;11、document.cookie。
