Example of how to insert HTML-insertadjacenthtml into HTML tags using strings

Source: Internet
Author: User
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> ");
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.