diff --git a/lib/node-htmlparser.js b/lib/node-htmlparser.js index b54ddb4..0c7da8c 100644 --- a/lib/node-htmlparser.js +++ b/lib/node-htmlparser.js @@ -249,8 +249,11 @@ Parser.prototype.parseTags = function Parser$parseTags () { prevElement.raw = prevElement.data = prevElement.raw + this._prevTagSep + element.raw; element.raw = element.data = ""; //This causes the current element to not be added to the element list } - else //Element is empty, so just append the last tag marker found - prevElement.raw = prevElement.data = prevElement.raw + this._prevTagSep; + else{ //Element is empty, so just append the last tag marker found + if (prevElement) { + prevElement.raw = prevElement.data = prevElement.raw + this._prevTagSep; + } + } } else //The previous element was not text if (element.raw != "")