A useful insertadjacenthtml method for modifying HTML

Source: Internet
Author: User

Add HTML content and text content before using the innerHTML and InnerText methods,

There are also insertadjacenthtml and insertAdjacentText methods recently found,

These two methods are more flexible and can insert HTML content and text content in the specified place.

The insertAdjacentText method is similar to the insertAdjacentHTML method except that only plain text is inserted and the parameters are the same

Prototype: insertadajcenthtml (Swhere,stext)

insertAdjacentHTML Method: Inserts an HTML tag statement at the specified place
Parameters:
Swhere: Specifies where the HTML tag statement is inserted, with four values available:
1.beforeBegin: Insert before the label starts

2.afterBegin: After inserting the tag start tag

3.beforeEnd: Before the label end tag

4.afterEnd: After inserting the tag end tag

Stext: What to insert



<script language= "javascript"
function myfun ()
{
  var obj = document.getElementById ("btn1");
  obj.insertadjacenthtml ("Afterend", "<br><input name=\" txt1\ ">");
}
</script>

<body>
  <input name= "txt";
  <input Id= "BTN1" name= "btn1" type= "button" value= "More ..." onclick= "myfun ()";
</body>

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.