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 :

Copy code The code is as follows:

var sHTML="
"
var sScript='


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:
Copy code The code is as follows:




< ;title>Untitled Document


safdsdaf time place




The above is the code I forwarded to others, below I will add a few more lines of code, which are also very classic. Maybe you can use them:
Copy the code The code is as follows:

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template