Home > Web Front-end > JS Tutorial > Completely master DOM attribute members and document flow

Completely master DOM attribute members and document flow

WBOY
Release: 2022-08-05 15:36:50
Original
1581 people have browsed it

This article brings you relevant knowledge about javascript. It mainly introduces issues related to DOM attribute members and document flow. It divides the form from top to bottom into rows and rows, and Arranging elements in each row from left to right is the document flow. Let's take a look at it. I hope it will be helpful to everyone.

Completely master DOM attribute members and document flow

[Related recommendations: javascript video tutorial, web front-end]

Document flow:

Divide the form into rows from top to bottom, and arrange the elements in each row from left to right, which is the normal flow/document flow.

Text stream:

The reading and output order of documents, which is the form of reading and outputting from left to right and top to bottom that we usually see.

The situation of breaking away from the document flow:

1. float float

The float will break away from the document flow but not the text flow. In other box models The text will still make way for it, > wrap around it

2. Position: absolute/fixed Absolute positioning

Absolute positioning will make the element break away from the document flow and the text flow. Other box model elements and the arrangement of text in them will ignore it

Document flow and text flow can be understood as positioning/position

DOM

JavaScript operates web pages Interface, the full name is "Document Object Model" (Document Object Model).

There are several concepts: document, element, node

The entire document is a document node

Each tag is an element node

Contained in The text in the element is a text node

Each attribute is an attribute node

Comments belong to comment nodes

DOM tree:

DOM tree is a structure

The so-called hierarchical structure refers to the relationship between elements

Father, son, brother

The tree output by the parser is composed of DOM elements and attribute nodes

When we say that the tree contains DOM nodes, it means that the tree is composed of elements that implement the DOM interface. These implementations include other properties required internally by browsers.

The hierarchical structure relationship remains unchanged after leaving the document flow

html DOM attributes

The attributes are nodes (HTML elements ) value, you can get or set it.

Programming interface

The HTML DOM can be accessed through JavaScript (and other programming languages).

All HTML elements are defined as objects, and the programming interface is object methods and object properties.

Methods are actions you can perform (such as adding or modifying elements).

Attributes are values ​​that you can get or set (such as the name or content of a node).

innerHTML property

The easiest way to get the content of an element is to use the innerHTML property.

The innerHTML attribute is useful for getting or replacing the content of an HTML element.

Example

The following code obtains the innerHTML of the

element with id="intro":

<html>
<body>
<p id="intro">Hello World!</p>
<script>
var txt=document.getElementById("intro").innerHTML;
document.write(txt);
</script>
</body>
</html>
Copy after login

Output result:

Completely master DOM attribute members and document flow

In the above example, getElementById is a method and innerHTML is a property.

The innerHTML attribute can be used to get or change any HTML element, including and .

nodeName attribute

The nodeName attribute specifies the name of the node.

nodeName is read-only

  • The nodeName of the element node is the same as the label name

  • The nodeName of the attribute node is the same as the attribute name The same

  • The nodeName of the text node is always #text

  • The nodeName of the document node is always #document

Note: nodeName always contains the uppercase tag name of the HTML element.

nodeValue attribute

The nodeValue attribute specifies the value of the node.

  • The nodeValue of the element node is undefined or null

  • The nodeValue of the text node is the text itself

  • The nodeValue of the attribute node is the attribute value

Get the value of the element

The following example will retrieve

Text node value of label:

Instance

<html>
<body>
<p id="intro">Hello World!</p>
<script type="text/javascript">
x=document.getElementById("intro");
document.write(x.firstChild.nodeValue);
</script>
</body>
</html>
Copy after login

Output result:

Completely master DOM attribute members and document flow

##nodeType attribute

nodeType property returns the type of node. nodeType is read-only.

The more important node types are:

Completely master DOM attribute members and document flow

[Related recommendations: javascript video tutorial, web front-end]

The above is the detailed content of Completely master DOM attribute members and document flow. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template