I have a div with id "test". Inside it is an iframe which has no id. I need to access the body contents of this iframe. How to do it using JS/Jquery?
Asked
Active
Viewed 5,926 times
1
-
Is the iframe source from the same domain as the main page? – nnnnnn Nov 02 '12 at 06:43
-
Yeah. Actually the iframe doesn't display any other HTML page. It is editable using an external JS. – Bhumi Singhal Nov 02 '12 at 06:45
-
Body contents means which html control you want to access from iframe page to main page? – Manikandan Sethuraju Nov 02 '12 at 06:51
2 Answers
1
Access it like this:
$('#test>iframe').contents.find('body') // This will get you body tag
0
jquery will do it.
var objiframe=$('#test').find('iframe');
you'll get iframe
in objiframe
then use objiframe
with selector to get or set attribute and contents of iframe.

Milind Anantwar
- 81,290
- 25
- 94
- 125