diff --git a/lib/parse.js b/lib/parse.js index b53a4fffb2..51ca038089 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -35,9 +35,9 @@ exports = module.exports = function parse(content, options, isDocument) { } else { // Generic root element var root = new domhandler.Document(content); - content.forEach(function (node) { - node.parent = root; - }); + + // Update the DOM using the root + exports.update(content, root); dom = root; } diff --git a/test/cheerio.js b/test/cheerio.js index 0523546906..865296b4c8 100644 --- a/test/cheerio.js +++ b/test/cheerio.js @@ -262,6 +262,13 @@ describe('cheerio', function () { expect($('ul')).to.have.length(3); }); + it('should allow loading a single element', function () { + var el = htmlparser2.parseDOM(food)[0]; + var $ = cheerio.load(el); + + expect($('ul')).to.have.length(3); + }); + it('should render xml in html() when options.xml = true', function () { var str = ''; var expected = '';