need like foreach in jQuery to take all the divs from all the iframes

空扰寡人 提交于 2019-12-25 04:17:50

问题


so the code that extracts the div from the iframe is made by @Adil like this:

$(window).load(function () {
        var filteredContents = $('.test').contents().find('.div_iframe').html();
        $('.test').contents().find('body').html(filteredContents);
});

HTML looks like this:

<iframe class="test" width="100%" height="100%" src="/message.html?msjId=268" style="height:100%;width:100%;">
<iframe class="test" width="100%" height="100%" src="/message.html?msjId=260" style="height:100%;width:100%;">

and the tables that should be displayed now, they should be two different tables, but at the moment is the same table for both msjId but duplicated from the first msjId...

Thanks in advance!

UPDATE:

i will explain more so i don't get close vote what i'm doing is that i have a table in the iframes that i want only to get without any headers or anything so the code above is filtering that to give me exactly that div that contains the table from the iframe and then displays it. my problem is if i have more than one iframe then the table is duplicated from the first iframe with the same info and there's no loop like foreach...


回答1:


When you have more then one elements you can use each to iterate through them, try this.

<iframe id="frame1" width="100%" height="100%" src="/message.html?msjId=268" style="height:100%;width:100%;">
<iframe id="frame2" width="100%" height="100%" src="/message.html?msjId=260" style="height:100%;width:100%;">

 $(window).load(function () {
     $('.test').each(function(){         

       var filteredContents1 = $(this).contents().find('.div_iframe').html();
       $(this).contents().find('body').html(filteredContents1);       

     });

 });


来源:https://stackoverflow.com/questions/12545825/need-like-foreach-in-jquery-to-take-all-the-divs-from-all-the-iframes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!