i need to split an HTML element based on a users selection like this :
<p> Hi , i need to <b>split <i> an [HTML] element </i> based on a users selection </b></p>
in first use :
<p> Hi , i need to <b>split <i> an </i> HTML <i> element </i> based on a users selection </b></p>
and in 2nd use :
<p> Hi , i need to <b>split <i> an </i></b></p>
HTML
<p><b><i> element </i> based on a users selection </b></p>
i have getSelectionHtml()
, replaceSelectionWithHtml(html)
from here .
also :
function range(){
var range = window.getSelection().getRangeAt(0);
var a = range.startContainer ;
els = [];
while (a.tagName != 'DIV') {
els.unshift(a);
a = a.parentNode;
}
}
//so i have els[0] = <p> element , els[1] = <b> element , els[2] = <i> element
please help .