Home >
Web Front-end >
JS Tutorial >
How to insert html content and text content at a specified place_javascript skills
How to insert html content and text content at a specified place_javascript skills
WBOY
Release: 2016-05-16 17:07:45
Original
1779 people have browsed it
dhtml provides two methods to add, insertAdjacentHTML and insertAdjacentText insertAdjacentHTML method: insert html tag statement at the specified place. Prototype: insertAdjacentHTML(swhere,stext) Parameters: swhere: Specify the place where html tag statements are inserted. There are four values available: 1.beforeBegin: Insert before the start of the tag 2.afterBegin: Insert after the tag start tag 3.beforeEnd: Insert before the tag end tag 4.afterEnd: Insert after the tag end tag stext: Content to be inserted Example :
The insertAdjacentText method is similar to the insertAdjacentHTML method, except that it can only insert plain text and has the same parameters.
These two attributes are quite applicable, especially in drawings and other places. They are used more. Its advantages It will not overwrite the original content. Let us assume that there is a DIV that already has content in it. Now we have to add content dynamically without overwriting the original content. So at this time this Things are very important, innerHTML will overwrite the original things. All HTML that appears in pairs can use this attribute, which is the same as innerHTML, such as ...,
....
, etc. There are these two attributes
Just to add: I just tried it and the innerHTML attribute is readable and writable. I used to know that innerHTML can insert content into nodes, but this attribute is also readable, that is to say What is saved in innerHTML is the html content of the node; look at the following code to fully understand:
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