views:

142

answers:

2

How can I grab a div from an iframe into a JS variable? Doesn't necessarily have to use jQuery.

+8  A: 
document.getElementById('IframeId').contentWindow.document.getElementById('DivId');
Tracker1
Excellent answer +1
Jose Basilio
Just remember that this (or any other method) won't work cross domain because of security restrictions
Mike Robinson
+9  A: 

In jQuery syntax, that would be $('iframe').contents().find('div'). (Substitute any specific ids/classes/other selectors you need, of course). Tracker1's answer should work fine for standard Javascript.

Greg Campbell
The jQuery approach +1
Jose Basilio
I prefer the jQuery approach myself... bear in mind, it breaks when going more than one iFrame deep (like in MS's SQL Reporting services, ugh).
Tracker1