1 reply [Last post]
tqmd1
tqmd1's picture
Offline
Regular
Pakistan
Last seen: 50 weeks 2 days ago
Pakistan
Timezone: GMT+5
Joined: 2011-10-15
Posts: 15
Points: 31

Dear Sir,

These codes work fine

<li><a href="" onclick="document.getElementById('div2').style.display='none';return false">Hide Div 2</a></li>

If use these line, then it do not work

<li><a href="" onclick="document.getElementById('div2','div3','div4','div5').style.display='none';return false">Hide Div 2</a></li>

I used more than one div in it.

Complete discussin is here
http://www.webdevforums.com/showthread. ... w-Hide-Div

Please help

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 22 hours 44 min ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5125
Points: 2722

Hi tqmd1, You can only get

Hi tqmd1,
You can only get one element at a time with getElementById.
So you will need to wrap it in a for loop or something.

Instead of calling getElementById call you own function that does the work for you.
Something like this should be close.
<li><a href="" onclick="hideStuff();return false">Hide Div 2</a></li>

function hideStuff(){
  var stuff = new Array('div2','div3','div4','div5');
  for(var i =0; i < stuff.length; i++){
    document.getElementById(stuff[1]).style.display='none';
  }
}