Insert an HTML element in a contentEditable element
问题 I have a contentEditable div where I want to insert HTML tags (a simple span element). Is there a cross browser solution that allows me to insert those tags over my div selection or cursor position. If something else is selected on the page (not in the div), I want to append the tag to the end of the div. Thanks 回答1: Here is a kickstart // get the selection range (or cursor position) var range = window.getSelection().getRangeAt(0); // create a span var newElement = document.createElement(