Luke Redpath
06-17-2003, 01:39 PM
My javascript knowledge is rather limited and I'm struggling with a simple show/hide script. The following works:
function Toggle(idtotoggle) {
if (document.getElementById)
{
var element = document.getElementById(idtotoggle)
element.style.display = "block";
}
}
This changes the style display attribute of an element from hidden (default inline style) to block. This is fine.
However, I want to add a simple if...else statement to this so that if the display attribute is hidden, it changes it to block, and vice versa. I've done this:
function Toggle(idtotoggle) {
if (document.getElementById)
{
var element = document.getElementById(idtotoggle)
if (element.style.display = "hidden");
{
element.style.display = "block";
} else
{
element.style.display = "hidden";
}
}
}
However this does not work. I get the javascript error:
"Could not get the display property. Invalid argument"
I'm baffled but I'm sure it's something rather simple.
Any help is appreciated, thanks.
function Toggle(idtotoggle) {
if (document.getElementById)
{
var element = document.getElementById(idtotoggle)
element.style.display = "block";
}
}
This changes the style display attribute of an element from hidden (default inline style) to block. This is fine.
However, I want to add a simple if...else statement to this so that if the display attribute is hidden, it changes it to block, and vice versa. I've done this:
function Toggle(idtotoggle) {
if (document.getElementById)
{
var element = document.getElementById(idtotoggle)
if (element.style.display = "hidden");
{
element.style.display = "block";
} else
{
element.style.display = "hidden";
}
}
}
However this does not work. I get the javascript error:
"Could not get the display property. Invalid argument"
I'm baffled but I'm sure it's something rather simple.
Any help is appreciated, thanks.