2016-02-25 61 views
0

我想弄清楚一種方法來選擇iFrame在下面的JSFiddle說'測試'。我試圖這樣做的方式如下,但它似乎並沒有工作。我無法選擇使用class/id的任何內容,因爲div是在我的網站中動態生成的。查找iFrame內容

$('.big-box').each(function(index) 
 
{ 
 
    if ($(this).find("div").find("iframe").contents().find("body").contents().length > 0) 
 
    { 
 
    console.log("Trigger"); 
 
    }; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
 
<div class="big-box"> 
 
    <iframe> 
 
    Other 
 
    </iframe> 
 
    <div> 
 
    <iframe> 
 
     <body> 
 
     Test 
 
     </body> 
 
    </iframe> 
 
    </div> 
 
</div>

回答

1

find("body")後刪除contents()

contents()將僅用於iframe,您不需要它用於其他DOM元素。