Get reference of window object from a dom element
Get a reference to the DOM node, use the ownerDocument
property to get a reference to the document, then read its defaultView
property (parentWindow
for IE8-) to get a reference to the window:
var $element = $('#elementId');
var element = $element[0];
// Assume that element exists, otherwise an error will be thrown at the next line
var doc = element.ownerDocument;
var win = doc.defaultView || doc.parentWindow;