Solved

Document.layers has no properties error

Posted on 2004-09-27
2
254 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
Comment Utility
change this:

   if (navigator.appName=="Netscape")

to this:

   if (document.layers)
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 125 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery, dropdown 4 34
Javascript loop through list 13 33
Condidional <a href = ....> 1 23
jQuery value within div undefined 3 17
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 …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

771 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

11 Experts available now in Live!

Get 1:1 Help Now