window.onload and getelementbyid returns null

I have a problem with my JS-onload function. The getElementById()-function returns NULL every time, but the div exists. I cannot see the bug... Here is the HTML-code: And the js-file which triggers the bug: function onLoad() { var element; Browser.detect(); alert('Engine: ' + Browser.browser); for (var i = 0; i < Style.configs.length; i++) { for (var c = 0; c < Style.configs[i].setup.length; c++) { if (Browser.browser == Style.configs[i].setup[c].engine) { element = document.getElementById(Style.configs[i].setup[c].size.flag); element.style.height = Style.configs[i].setup[c].size; break; } else if (Style.configs[i].setup[c].engine == "Default") { element = document.getElementById(Style.configs[i].setup[c].size.flag); element.style.height = Style.configs[i].setup[c].size; return; } } } } window.onload = onLoad; And at last, the style.js-file: var Style = { configs : [ { flag : "header", setup : [ { engine : "Gecko", size : 37 }, { engine : "Default", size : 38 } ] } ] };
Can you debug by setting a breakpoint to see the value of Style.configs[i].setup[c].size.flag? Then make sure that the id is what you were expecting to see

以上就是window.onload and getelementbyid returns null的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏