jquery - Replace String to html content using javascript -


i have string renders json "i $1$ frontend developer works @ $2$ $3$".

now, want replace $1$,$2$ , $3$ dynamic html input text boxes.so, output should

<-input textbox here> frontend developer works @ <-input textbox here> <-input textbox here>.

var str = "i $1$ frontend developer works @ $2$ $3$"; var newstr = ""; for(var i=0;i<3;i++){ var id = '$'+i+'$'; if (str.indexof(id) >= 0){    newstr = str.replace(id, $.parsehtml('<div><input type="text"  id="input-"+i/></div>')); } 

i tried use string replace method.but seems work strings.any other methods can use achieve using javascript/jquery

    <div id="div1">     </div>      <script type="text/javascript"> var data = "i $1$ frontend developer works @ $2$ $3$";      //include jquery before code       $(function(){         data.replace('$1$','<input type="text" />').replace('$2$','<input type="text" />').replace('$3$','<input type="text" />');        });     $('#div1').html(data);     </script> 

Comments