2012-01-17 23 views
0

我在Chrome上有這個奇怪的問題 - 我的網頁上我使用Mootools注入元素,特別是包含jwplayer視頻的lightbox。關於chrome的問題是指的是一個元素,即。 $( 'grid_01');第二次點擊它時返回null。爲了解決這個問題,我試圖測試元素爲空,並重新注入它Chrome瀏覽器 - Mootools注入失敗,null元素

  var ss = $('holderdiv'); 
      var x = $('mb_inline_0_-1'); 
      if(x == null) 
      { 
       var el = new Element("div", {id: "mb_inline_0_-1"}); 
      //if this line below runs without error... 
       ss.inject(el); 

      } 
      //.........why would x2 be null? 

      var x2 = $('mb_inline_0_-1'); 

Chrome說它爲空。有什麼我可以做,以確保DOM更新?

謝謝

回答

1

你的意思是使用抓鬥,而不是注入。

ss.grab(el); // Or el.inject(ss); 

您的代碼已被ss注入到el中,它永遠不會連接到DOM。

1

注入新創建的Element的格式爲newElement.inject(existingElement, position);

你的情況

所以,如果你正計劃注入新創建的div(在el包含)到$('holderdiv'),應該正是如此做:

var el = new Element('div', { 
    . . . 
}); 
el.inject('holderdiv', 'bottom'); // Although 'bottom' is assumed if nothing is passed 
相關問題