admin管理员组文章数量:1414604
I was checking the JS console out and it helped me fix a few minor issues, but I would like to know if this warning is anything to seriously worry about?
This is the code which gives the error:
<script type="text/javascript"
src=".js"></script>
<script src=".js" type="text/javascript"></script>
<script>
function layerSetup(id,visibility){
if(document.getElementById){
this.obj = document.getElementById(id).style;
Uncaught TypeError: Cannot read property 'style' of null
Uncaught TypeError: Cannot read property 'style' of null
<!--Includes many more of the same "Cannot read property 'style' of null messages -->
this.obj.visibility = visibility;
return this.obj;}
else if(document.all){
this.obj = document.all[id].style;
this.obj.visibility = visibility;
return this.obj;}
else if(document.layers){
this.obj = document.layers[id];
this.obj.visibility = visibility;
return this.obj;}
}
function visVisible(param){
new layerSetup(param,'visible');
}
function visHidden(param){
new layerSetup(param,'hidden');
}</script>
I cannot really figure out why this is happening and whether it's something I should worry about since our Rug categories function fine. Can anybody offer any insight? I apologize for not offering any of my own explanations but I didn't write this JS a former co-worked did and it's now up to me to debug every mistake he made. It's a learning process but I'm still somewhat new to this ..
I was checking the JS console out and it helped me fix a few minor issues, but I would like to know if this warning is anything to seriously worry about?
This is the code which gives the error:
<script type="text/javascript"
src="https://www.safaviehhome./product_images/locations/js/jqgalscroll.js"></script>
<script src="https://www.safaviehhome./product_images/mainnav/stuHover.js" type="text/javascript"></script>
<script>
function layerSetup(id,visibility){
if(document.getElementById){
this.obj = document.getElementById(id).style;
Uncaught TypeError: Cannot read property 'style' of null
Uncaught TypeError: Cannot read property 'style' of null
<!--Includes many more of the same "Cannot read property 'style' of null messages -->
this.obj.visibility = visibility;
return this.obj;}
else if(document.all){
this.obj = document.all[id].style;
this.obj.visibility = visibility;
return this.obj;}
else if(document.layers){
this.obj = document.layers[id];
this.obj.visibility = visibility;
return this.obj;}
}
function visVisible(param){
new layerSetup(param,'visible');
}
function visHidden(param){
new layerSetup(param,'hidden');
}</script>
I cannot really figure out why this is happening and whether it's something I should worry about since our Rug categories function fine. Can anybody offer any insight? I apologize for not offering any of my own explanations but I didn't write this JS a former co-worked did and it's now up to me to debug every mistake he made. It's a learning process but I'm still somewhat new to this ..
Share Improve this question asked Jun 4, 2012 at 19:46 LivingstonLivingston 311 gold badge1 silver badge5 bronze badges 1-
Without seeing your markup or how
layerSetup
is being called, I'd guess that you are trying to get an element by ID that does not exist in your document. – ajm Commented Jun 4, 2012 at 19:50
2 Answers
Reset to default 2This could be happening for two reasons.
- Somewhere on the page the
layerSetup
function is being called withnull
as one of the parameters. - An element with the id being passed the the
layerSetup
function does not exist on the page.
In the Chrome dev console you can click Pause on All Exceptions
, a button in the bottom left bar with a pause symbol. This will help you to determine what the parameters are that are being passed to the function.
Avoid document.all
http://www.javascripttoolbox./bestpractices/
http://simonwillison/2003/Aug/11/documentAll/
本文标签: Cannot read property 39style39 of nullin Chrome39s Javascript ConsoleStack Overflow
版权声明:本文标题:Cannot read property 'style' of null - in Chrome's Javascript Console - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745194023a2647049.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论