Is there a way to select a DIV in the parent window using jQuery?
For example:
Main page contains this,
<div id="testdiv"></div>
Popup page has a form with some options and an 'Apply' button. When the user clicks apply it affects the style attribute on the main page.
Something along the logic of,
parent.$("#testdiv").attr("style", content from form);
The parent() method returns the direct parent element of the selected element. The DOM tree: This method only traverse a single level up the DOM tree. To traverse all the way up to the document's root element (to return grandparents or other ancestors), use the parents() or the parentsUntil() method.
jQuery parent() Method The parent() method returns the direct parent element of the selected element.
The :parent Selector page on jQuery says: Select all elements that have at least one child node (either an element or text). So $('div') would select all divs and $('div:parent') would select only those with children.
parent() method returns the direct parent element of the selected one. This method only traverse a single level up the DOM tree. parents() method allows us to search through the ancestors of these elements in the DOM tree.
Use the context-parameter
$("#testdiv",parent.document)
But if you really use a popup, you need to access opener instead of parent
$("#testdiv",opener.document)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With