javascript function

They have: 426 posts

Joined: Feb 2005

When i click on a div this funciton is called, it will show a table 1 out of three however i cannot figure out how to display: none to the present table when another table is called?

function show(id)
{
el = document.getElementById(id);
if (el.style.display == 'none')
{
el.style.display = '';
el = document.getElementById('more' + id);
el.innerHTML = 'less...';
} else {
el.style.display = 'none';
el = document.getElementById('more' + id);
el.innerHTML = 'more...';
}
}
'

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

benf wrote: when another table is called?

I don't understand this bit of the question. Do you mean when another table is shown? You could create another function called [incode]hide(id)[/incode] then in the onclick event do:

hide('table1');
hide('table2');
show('table3');
'

Does that make sense?

a Padded Cell our articles site!

They have: 426 posts

Joined: Feb 2005

I think i need to adjust this if statement

function show(id)
{
el = document.getElementById(id);
if (el.style.display == 'none')
{
el.style.display='';

               // here im trying to say if the table does not have that id close it
if(document. getElementsByTagName != id) {
el.style.display =='none';
}
}else {
el.style.display='none';
}
}
'

my navigation works ok, when you click on anyone tab the table associated with that tab shows and disappears when clicked agian but when you click another tab that table appears below it and so on.
what i really want is when clicking another tab the table that is showing is replaced by the next table.

http://www.yahoo.com/ take the yahoo homepage for example look at the tab system.

I just though that the function could work out which id is associated with which table and hide all others when another is called.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.