Replacing the contents of a specific id tag of an html string in javascript -


i have js string this:

var html_string = "<h3 id='title'>abc</h3><h5 id='subtitle'>xyz</h5>"; 

this string put codemirror iframe makes visible. want let user change title , subtitle in easy way <input> fields. how can replace these specific texts using id tags?

for example if title input "hello", subtitle input "world" , current string 1 shown above new string should become:

"<h3 id='title'>hello</h3><h5 id='subtitle'>world</h5>" 

should use regex? structure of regex this?

note can't replace("abc", "hello") need change text based on id of tag.

for multiple can use class, not id

$("h3.title").each(function(index){     if($(this).text()=="hello"){         $("h5.subtitle:eq("+index+")").replace("xyz",$("input#id").val());     } }) 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -