This article describes the difference between innerHTML and pasteHTML in JS. Share it for your reference, as follows:
innerHTML is an attribute that can obtain or set the HTML content in this element. It can be used by any element that can contain HTML child nodes.
pasteHTML() is a method that replaces text or HTML within the specified text area. This method must be applied to a createdTextRange() or document.selection.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 did not select the text to link!'); }}</Script>NetEase Sina Sohu<br><br><input type="button" value="Add link" onclick="addLink();">For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript traversal algorithms and techniques", and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.