jquery - Convert HTML object back to string -


i convert string of html object can manipulate this

var htmlstr = "<div><span>testing</span></div><h1>heading</h1><div class='two'>sjdufhs</div>"; var htmldom = $(htmlstr).find("h1").remove(); var newhtmlstr = ??? 

question: how can convert htmldom string after manipulation?

i have tried following: https://stackoverflow.com/a/652771/3758078 converts first element found, , not rest. if theres no element containing other elements.

you need save result of parsing html variable, can html after modifying it.

you need wrap original html in element, because getting html later .html() return html of first element in collection.

var htmlstr = "<div><span>testing</span></div><h1>heading</h1><div class='two'>sjdufhs</div>";  var dom = $('<div>' + htmlstr + '</div>');  dom.find("h1").remove();  var newhtmlstr = dom.html();  console.log(newhtmlstr);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -