I want to parse a html string to jQuery object then find an element by ID.
I tried 3 ways bellow, but only the last works. I don't know why the others not works?
var html = "<html><body><div id='main'></div></body></html>";
// Not work, return 0
console.log($(html).find('#main').length);
// Not work, return 0
console.log($($.parseHTML(html)).find('#main').length);
// Works, return 1
console.log($("<html/>").html(html).find('#main').length);
Here is the sample: http://jsfiddle.net/nbyofkam/2/