document.body is null

牧云@^-^@ 提交于 2019-12-31 04:02:10

问题


I've got a page where I'm using Mootools 1.2.4 and MediaboxAdvanced as a lightbox. I can't seem to get the thing working because of a particular javascript error

document.body is null

at the initialization of Mediabox:

$(document.body).adopt(
     $$([
          overlay = new Element("div", {id: "mbOverlay"}).addEvent("click", close),
          center = new Element("div", {id: "mbCenter"})
     ]).setStyle("display", "none")
); 

The page is here. If yo uclick on the guy's name, picture, or the More Info button on the bottom right, it is supposed to launch the Mediabox. Via Firebug, I have confirmed that the CSS is loading, mootools is loading, and the Mediabox script is loading; all the paths to images and everything are correct as well.

Any ideas?


回答1:


You may only be able to use $ on an element returned from getElementById. A simple workaround is to instead use $$.

$$('body')[0].adopt...


来源:https://stackoverflow.com/questions/2363605/document-body-is-null

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