2015-04-17 119 views
-1
$.colorbox({ href: previewLink, iframe: true, width: "90%", height: "90%" }); 

我使用上面的代碼來調用colorbox。一旦顯示顏色框,我想訪問和colorbox內的元素,然後更改css。colorbox內的訪問元素

但是我無法訪問colorbox中的元素。

我試過如下:

$(function() { 

    'use strict'; 

    setInterval(
     function() { 

      console.log("logging..."); 

      var elements = document.getElementsByClassName("className"); 
      if (elements.length > 0) { 
       console.log("Found element"); 
      } 

     }, 1000); 

}); 
+2

假設您的瀏覽器支持'getElementsByClassName'(ie9 +),您可以在小提琴中複製嗎?沒有看到HTML被渲染,很難知道任何元素是否具有'className'類 – atmd

回答

0

不要使用超時用於此目的,總是找事件。在顏色框富人onOpen事件(CTRL+F "Callbacks"),我認爲適合您的需要:

$.colorbox({ 
    href: previewLink, 
    iframe: true, 
    width: "90%", 
    height: "90%", 
    onOpen: function() 
    { 
     debugger; 
     $("#colorbox").find(); // Find desired element 
    } 
}); 

Fiddle

此外,爲什麼你使用getElementsByClassName,如果你已經在你的網頁上有jQuery?爲什麼不是.find()