javascript - JQuery, how to append div after selected text in html? -
hi possible add div after selected text? jquery or java-script , rangy js
i'm try below code not working..
function pin_surroundrange() { var range = getfirstrange(); //get selected text via rangy js if(range != null) { $( '#content_area ('+range+')' ).replacewith( ''+range+'<div><input type="text" /></div>' );} }
the steps i'd use are:
- get selected range
- collapse range end
- call range's
insertnode()
method
code:
var div = document.createelement("div"); div.appendchild( document.createelement("input") ); var sel = rangy.getselection(); if (sel.rangecount > 0) { var range = sel.getrangeat(0); range.collapse(false); range.insertnode(div); }