how to access parent window object using jquery?

How to acess parent window object using jquery?

This is my Parent window variable , I want to set its value after closing child window .

$('#serverMsg').html('some text here');

window.opener.$("#serverMsg")

If you are in a po-up and you want to access the opening window, use window.opener. The easiest would be if you could load JQuery in the parent window as well:

window.opener.$("#serverMsg").html // this uses JQuery in the parent window

or you could use plain old document.getElementById to get the element, and then extend it using the jquery in your child window. The following should work (I haven't tested it, though):

element = window.opener.document.getElementById("serverMsg");
element = $(element);

If you are in an iframe or frameset and want to access the parent frame, use window.parent instead of window.opener.

According to the Same Origin Policy, all this works effortlessly only if both the child and the parent window are in the same domain.


or you can use another approach:

$( "#serverMsg", window.opener.document )