Solved

Document.layers has no properties error

Posted on 2004-09-27
2
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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 my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

749 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