Example of the insertadjacenthtml Method
Previously, the innerhtml and innertext methods were used to add HTML content and text content. Recently, insertadjacenthtml and insertadjacenttext methods were found to be more flexible, you can insert HTML content and text content in a specified place.
Insertadjacenthtml method: insert the HTML Tag statement in the specified place
Prototype:Insertadajcenthtml (swhere, stext)
Parameters:
Swhere: specifies where HTML tag statements are inserted. Four values are available:
1. beforebegin: before the start of the tag
2. afterbegin: inserted after the tag starts Marking
3. beforeend: insert to the end tag of the tag.
4. afterend: insert to the end tag of the tag.
Stext: content to be inserted
<HTML>
<Head>
<Script language = "JavaScript">
Function Myfun (){
VaR OBJ = Document. getelementbyid ("btn1 ");
OBJ. insertadjacenthtml ("afterend", "<br> <input name =" txt1 "> ");
}
</SCRIPT>
</Head>
<Body>
<Input name = "TXT">
<Input id = "btn1" name = "btn1" type = "button" value = "more" onclick = "myfun ()">
</Body>
</Html>
**************************************** ************************
Function Addsome ()
{
Document. All. paral. insertadjacenthtml ("afterbegin", "Document. All. paral. insertadjacenthtml ("beforeend", "<H2> insert content in the container after text </H2> ");
Document. All. paral. insertadjacenthtml ("beforebegin", "<H4> insert content outside the container before text Document. All. paral. insertadjacenthtml ("afterend", "<H5> insert content outside the container after text </H2> ");
}