Q:

ParseHTML in firefox addon using parseFragment

Here's the parseFunction
Ajax:
{
    ParseHTML: function(aHTMLString)
    {
        var html = document.implementation.createDocument("http://www.w3.org/1999/xhtml", "html", null),
        body = document.createElementNS("http://www.w3.org/1999/xhtml", "body");
        html.documentElement.appendChild(body);

        body.appendChild(Components.classes["@mozilla.org/feed-unescapehtml;1"]
            .getService(Components.interfaces.nsIScriptableUnescapeHTML)
            .parseFragment(aHTMLString, false, null, body));

        return body;
    }
}

Here I'm trying to use the parse in a http response (to sanatize the code):
var newdoc = Ajax.ParseHTML(o.responseText);

But, when I try to use:
newdoc.getElementById('teste');

It returns me the error: TypeError: newdoc.getElementById is not a function
Am I doing somthing wrong? It has something to do with documentType or something? 
Also, this function removes all href="" attributes in a tags for example, maybe the problems are related ...

A:

getElementById is only defined on the document object, because an ID has to be unique in a document. For this reason, it did not make sense to define getElementById on an element object.
The following methods will work:
newdoc.querySelector('#teste');
newdoc.ownerDocument.getElementById('teste');

As for creating a document, you might be interested in the DOMParser, or want to use document.implementation.createHTMLDocument (with HTML).

