SamDZ SamDZ - 1 year ago 89
jQuery Question

How to retrieve specefic div class in iframe tag?

I try to retrieve somethingclass2 class retrieving in an iframe tag with jQuery:

enter image description here

this code does not work for me:

$("document").ready(function () {
console.log($('iframe html body .somethingclass1 .somethingclass2'));
});


thanks

Answer Source

Because your JS code and HTML code don't seem to correlate, this is only a guess but... is your iframe content coming from another domain?

If so, you can't get to the elements inside it. At least not without breaking browser security. If you could, it'd be an enormous security hole.

However, if the iframe content is from the same origin as the containing page, you can do

$("iframe.someiframe").contents().find("div.foo")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download