I cannot wrap my head around this. I want to duplicate the text that's just been written and insert it at the cursor point. span.className='newSpan'
gets inserted correctly as a span, but then adding span.innerHTML=content
afterwards removes the span. Other combinations have resulted in a "Failed to execute 'insertNode' on 'Range': parameter 1 is not of type 'Node'" error.
if (e.keyCode == 32) {
var cursor = document.getSelection().getRangeAt(0);
var content = document.getSelection().anchorNode.data
var span = document.createElement("span")
span.className = 'newSpan'
// and what I'd basically like to do:
span.innerHTML = content
cursor.insertNode(span)
Attempting to do something like $('.newSpan').text(content)
afterwards also doesn't work.