-1

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 .

Community
  • 1
  • 1
talkhabi
  • 2,669
  • 3
  • 20
  • 29

1 Answers1

0

If you just want replace the particular string. You can try this.

("<p> Hi , i need to <b>split <i> an  [HTML] element </i> based on a users selection </b></p>").replace(/[HTML]/g, '</i> HTML <i> ')
AmanVirdi
  • 1,667
  • 2
  • 22
  • 32