Get document object from a child element

element.ownerDocument will give you a reference to the document to which any DOM element belongs.


Yes, the document object is the parent of the <HTML> element (at least in Firefox). Find it like this:

function FindDoc(el) {
    while(el.parentNode) {
        el = el.parentNode;
    }
    return el;
}