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 ();">