I am returning a large chunk of HTML from an $.ajax
call. The string coming from PHP has two line breaks at the beginning, e.g.
$data = \"
<
My HTML strings did not have any top-level text nodes, or so I thought... I found the issue was just extra whitespace. This has worked for me, and feels better than filtering out the empty nodes later:
$($.parseHTML($.trim(html_string)))
The problem seems to be caused by the text node in the collection you can filter it out with .filter('*')
var $html = $($.parseHTML(data)).filter('*');