Solved

Document.layers has no properties error

Posted on 2004-09-27
2
255 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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now