How to create a node and pass it to a function?

63 Views Asked by At

I have the following:

<div contenteditable="true">
    <p>Here is some text blah <span class="tag">meme</span> hello world.</p>
</div>

What I want to do is set the cursor after the span. I can use the following but this doesn't let me tell the cursor to go after the span:

    var sel = window.getSelection();
    var textNode = document.getElementById("comment_content_new").firstChild;
    var range = document.createRange();
    range.setStart(textNode, 7);
    range.collapse(true);
    sel.removeAllRanges();
    sel.addRange(range);

Any ideas how I can tell var textNode to go after the span?

Thanks

1

There are 1 best solutions below

0
On

The easiest way would be with jquery

$("span").after(textNode);