Get document object from a child element

JavascriptJqueryDom

Javascript Problem Overview


Let's assume I have a jQuery object of a DIV element in body. I'd like to obtain document object by traversing. Can it be possible ?

Note: window.document is not a option in my case.

Thank you.

Javascript Solutions


Solution 1 - Javascript

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

Solution 2 - Javascript

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;
}

Solution 3 - Javascript

firstElementChild The first child that is an element node Traversal module.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOzgurView Question on Stackoverflow
Solution 1 - JavascriptcasablancaView Answer on Stackoverflow
Solution 2 - JavascriptpalswimView Answer on Stackoverflow
Solution 3 - JavascriptAndrew CollinsView Answer on Stackoverflow