Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1640 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     Javascript :

Hide all divs, show one using getElementsByTagName("div")

Thread title: Hide all divs, show one using getElementsByTagName("div")
     
    Thread tools Search this thread Display Modes  
Prev Previous Post   Next Post Next
08-03-2008, 03:13 PM
#1
Avarus is offline Avarus
Avarus's Avatar
Status: Junior Member
Join date: Aug 2007
Location: Apeldoorn, The Netherlands
Expertise:
Software:
 
Posts: 29
iTrader: 0 / 0%
 

Avarus is on a distinguished road

  Old  Hide all divs, show one using getElementsByTagName("div")

Hi, lately I've made a navigation menu that operates through invisible divs that can become visible. By default, all divs are invisible. When you point your mouse over a menu element, the appropiate div shows up. When you point your mouse over another element, the div will hide and another div shows up... At least, that's the idea.

This technique works smoothly when working with a static menu, but when the menu is dynamicaly rendered by PHP, the javascript has to become "dynamic" too. I thought I found a solution for that, but it isn't working as it should.

Code:
function menu(id) 
 {
 var divall = document.getElementsByTagName("div");
 if(divall.className == "menu")
  {
  divall.style.display = "none";
  }
 
var div = document.getElementById(id);
div.style.display= "block";
 
 return false;
   }
When you mouseover an element, the function is invoked by onmouseover="menu('dynamic_name')". This code should first hide all divs with the classname "menu". Then it picks the div with the id "dynamic_name" and chances its display into "block". The latter part works well, but in the first part, something is wrong: the divs won't hide.

I think the problem lies in the fact that divall is an array, but I'm not very good in JS, so I hope you guys can help me out.

     


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed