Adam Ware
Adam Ware

Reputation: 1202

Loop through multiple elements from an Iframe

I have content loaded into a hidden iframe on a page and I'm wanting to loop through multiple elements on a page and get text using jquery.

Here is my current code:

$('#myiFrame').contents().find('div.air').each(function (index) {
       alert($(this).text());
     });

It only seems to find the one div with the class of 'air', although there is two divs on the page. How is my code wrong ?

Edit: I should say their are two 'div.air' on the page not under the same parent.

HTML it something like :

<section id="blah">
<div class="air"> text here </div>
</section>
<section id="blah2">
<div class="air"> text here </div>
</section>

Upvotes: 1

Views: 3238

Answers (1)

Adam Ware
Adam Ware

Reputation: 1202

Worked out my own answer:

$('#iframe').contents().find('.air').each(function(){

    var foo = $(this).html();
    //do your Stuff here

});

Upvotes: 2

Related Questions