javascript - How to modify html string using jQuery -


i try use jquery modify html template.

for example:

var d = '<div class="a"><div class="b"></div><div class="c"></div></div>';  var html = $(d).find(".b").html("bbbbb");  console.log(d);   // want new html  

in above, want

'<div class="a"><div class="b">bbbbb</div><div class="c"></div></div>'

how can implement case? please suggest.

so here code:

var d = '<div class="a"><div class="b"></div><div class="c"></div></div>';  var html = $(d).find(".b").html("bbbbb").end()[0].outerhtml;  console.log(html); 

note key use .end(), pop off context of <div class="b"> created .find() operation , return $(d), allows full html using .outerhtml on raw dom node.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -