Examples of differences between innerHTML and pasteHTML in JS: innerhtmlpastehtml

Source: Internet
Author: User

Examples of differences between innerHTML and pasteHTML in JS: innerhtmlpastehtml

This article describes the differences between innerHTML and pasteHTML in JS. We will share this with you for your reference. The details are as follows:

InnerHTML is an attribute that can be used to obtain or set the HTML content of the element. It can be used by any element that can contain HTML subnodes.

PasteHTML () is a method that replaces text or HTML in the specified text area. This method must be applied to a createTextRange () or document. selection. on the region created by createRange ()

Example:

<Script Language = "JavaScript"> function addLink () {var oRange = document. selection. createRange (); if (oRange. text! = '') {Var oUrl = window. prompt ('link URL... ', 'HTTP: // www.163.com/'); var oHtml = '<a href =' + oUrl + 'target = _ blank> '+ oRange. text + '</a>'; oRange. pasteHTML (oHtml);} else {window. alert ('You have not selected the text to add a link! ') ;}</Script> Netease Sina Sohu <br> <input type = "button" value = "add link" onclick = "addLink ();">

Related Article

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.