reverse of jQuery.parseHTML

javascript, jquery

Solution

A simple function

function htmlToSource(selector){
 return $('<div />').append($(selector).clone()).html();
};

htmlToSource('body');

Problem

`jQuery.parseHTML()` produces an array. I'm looking for a way to convert it back to string. This is my top question. Is `parseHTML()` the only method to treat a string as html? Bassically, I was parsing my string as html so that I can use `find()` function of jQuery to match a certain element and then perfrom a replacement only on that portion of the code (see my previous question for more details). So, is parsing to html necessary for that?

Original source

Related problems