Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Document.layers has no properties error

Posted on 2004-09-27
2
Medium Priority
?
264 Views
Last Modified: 2012-08-13
I have the following code that works OK in IE, but I have just tried it in Firefox and I get the following error:
"Document.layers has no properties"
and the line is:
document.layers[i].visibility="hide";

I do not understand Javascript.  Could anyone explain if and how I can get the Javascript to run?


function closeAllMenusExcept(MenuID)
{
var NoOfMenus=10
      for (i=0; i<NoOfMenus; i++ )
      {
        if (navigator.appName=="Netscape"){
        if (i != MenuID){
          document.layers[i].visibility="hide";
        }else{
          document.layers[i].visibility="show";
        }         
      }else{
          var what="menu" + i
        if (i != MenuID){
//              alert(document.all.item(what).innerHTML)
          document.all.item(what).style.visibility="hidden";
        }else{
          document.all.item(what).style.visibility="visible";
        }
        }
      }
}
0
Comment
Question by:perrybond
  • 2
2 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 12159459
change this:

   if (navigator.appName=="Netscape")

to this:

   if (document.layers)
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 375 total points
ID: 12159475
function closeAllMenusExcept(MenuID)
{
var NoOfMenus=10
     for (i=0; i<NoOfMenus; i++ )
     {
       if  ( document.layers ){
        if (i != MenuID){
          document.layers[i].visibility="hide";
        }else{
          document.layers[i].visibility="show";
        }        
      }else if ( document.all ){
         var what="menu" + i
        if (i != MenuID){
//            alert(document.all.item(what).innerHTML)
          document.all.item(what).style.visibility="hidden";
        }else{
          document.all.item(what).style.visibility="visible";
        }
       }
     }else {
         var what="menu" + i
        if (i != MenuID){
//            alert(document.all.item(what).innerHTML)
          document.getElementById(what).style.visibility="hidden";
        }else{
          document.getElementById(what).style.visibility="visible";
        }
       }
     }
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question