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
Post a Comment