Search code examples
jqueryjquery-selectorspopupparent

jQuery select element in parent window


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

Solution

  • 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)