In many cases, innerHTML or innerText is used. Currently, direct dom operations are popular. You can choose one as needed. Var bq = document. getElementsByTagName ("tag or ID name") // ID is a unique and non-unique group. A tag may return an array.
P = document. createElement ("p ");
... Set the CSS style
Bq. appendChild (p); // If the ID is unique, you only need this! Insert p layer after bq
Bq [0]. appendChild (p); // If the tag is used before! Array and subscript! Insert p layer after bq
Bq. insertBefore (p); // If the ID is unique, you only need this! Insert p Layer Before bq
Bq [0]. insertBefore (p); // If the tag is used before! Array and subscript! Insert p Layer Before bq
Document.getelementbyid('navition'developer.style.css Text = 'your CSS Code ';
// Copy a p
Var bq = document. getElementById ("Copy") // ID is a unique and non-unique group. The tag is not unique and an array may be returned.
ObjDiv = document. createElement ("p ");
ObjDiv. id = bq. id + Copy;
ObjDiv. style. position = "absolute"
ObjDiv. style. left = "200px"
ObjDiv. style. top = "200px"
ObjDiv. innerHTML = bq. innerHTML;
Bq. appendChild (objDiv );
Test1 test2
Test1 test2
In JS, you can use:
Test. innerHTML: All content from the starting position of the object to the ending position, including the Html Tag.
In the preceding example, the value of test. innerHTML is
Test1 test2
Test1 test2
Test. innerText: content from the starting position to the ending position, but it removes the Html Tag
In the preceding example, the value of text. innerTest is "test1 test2", in which the span tag is removed.
Test. outerHTML: not only contains all the content of innerHTML, but also contains the object tag itself.
In the preceding example, the value of text. outerHTML is
Test1 test2
Test1 test2
Complete example:
The Code is as follows:
Test1 test2
InnerHTML content
InerHTML content
OuterHTML content
Test1 test2
InnerHTML content
InerHTML content
OuterHTML content
Note:
InnerHTML is a W3C standard attribute, while innerText is only applicable to IE browsers. Therefore, try to use
InnerHTML, rather than innerText. to output content without HTML tags, you can use innerHTML to obtain
After the content of the HTML Tag is removed using a regular expression, the following is a simple example that complies with W3C standards:
The Code is as follows:
Test1 test2
/Gim, '')"> no html, compliant with W3C standards
Test1 test2
/Gim, '')"> no html, compliant with W3C standards
Related Articles
Javascript dom operations details js enhancements