views:

16932

answers:

6

I have an iframe and I wrote this code

window.parent.document.getElementById('parentPrice').innerHTML

to access parent element. How to get the same result using jquery?
UPDATE: Or how to access iFrame parent page using jquery?

+37  A: 

To find in the parent of the iFrame use:

$('#parentPrice', window.parent.document).html();

The second parameter for the $() wrapper is the context in which to search. This defaults to document.

Pim Jager
Ok great I could help.
Pim Jager
Great answer, saved my time, thanks :)
Amr ElGarhy
Cool - you acknowledged the thanks before he thanked you.StackOverflow having problems with timezones maybe?
belugabob
thanks a lot...
Ashish Rajan
You could also do: $(window.parent.document).find("#parentPrice").html();
jhorback
@belugabob It's a wizzard's fault.
Erik Escobedo
+8  A: 

how to access iFrame parent page using jquery

window.parent.document.

jQuery is a library on top of JavaScript, not a complete replacement for it. You don't have to replace every last JavaScript expression with something involving $.

bobince
+1. jQuery is great, but lots of answers to simple problems seem to be 'use jQuery'. If you're loading the library anyway, fine, but don't load it one task. Also, people seem concerned about JS perf, then use an API on top of JS to do things easily possible (and possibly faster) without the API.
Grant Wagner
A: 

Good stuff

A: 

If have an iframe inside my HTML document. I would like to access with jQuery the parent document of the iframe. The following Code works fine in Firefox. But Safari just stays inside the iframe and doesn`t parse the parent element??? (latest Safari version 4.0.4) Thanks for your help.

var attr = $("html",window.top.document).html();

Stephan
A: 

Thanks $('#parentPrice', window.parent.document).html(); this works for me

ssoni27
you can add this as a comment not as an answer, this is not a forum website.
Amr ElGarhy
Why was this downvoted? It's the correct answer
Chuck Conway
because it is just saying that the answer provided which was chosen by the OP worked...
davidsleeps
A: 

in parent window put :

<script>
function ifDoneChildFrame(val)
{
   $('#parentPrice').html(val);
}
</script>

and in iframe src file put :

window.parent.ifDoneChildFrame('Your value here');
stieven