Re: toggle several elements
- From: "BD" <JustMe@xxxxxxxxxxx>
- Date: Tue, 4 Dec 2007 09:43:41 -0800
"Anthony Jones" <AnthonyJones@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:72BB224D-9E5D-4714-94E1-823B07E0C796@xxxxxxxxxxxxxxxx
Hi Anthony.
"BD" wrote:
Hi all.
I currently use a js toggle function that works well for toggleing the
visibility of images div's &etc. with the only parameter being the
element
to toggle. Called using somthing like
onclick="toggle('div1') + toggle('div2')"
Now I need to make some changes because the next series of pages will
have
multiple elements (all divs) to be toggled. I need to have it toggle the
current element to hidden and the linked element to visible.
I seem to recall something like "toggle(document.getelementbyid.this)".
Is
that correct? If not could someone set me straight or even show a better
function please.
Try this:-
function toggle(displayDivID)
{
this.style.display = "none";
document.getElementById(displayDivID).style.display = "block"
}
call like this:-
onclick="toggle.call(this,'nextDivID')"
An alternative would be to track the ID of the currently displayed div in
a
variable so you can continue to call toggle as you have been. However
that
requires that an initial call to toggle be made onload with the ID of the
first div.
var msCurrentDivID = null;
function toggle(displayDivID)
{
if (msCurrentDivID )
document.getElementByID(msCurrentDivID).style.display = "none"
msCurrentDivID = displayDivID
if (msCurrentDivID )
document.getElementByID(msCurrentDivID).style.display = "block"
}
--
Anthony Jones - MVP ASP/ASP.NET
Just to bring you up to date here is how I handled this.
Since I already had a function to toggle the div by id, and since the divs
in question all had the same class, I just added a function that hides all
of the divs of that class and then calls the toggle function to display the
div I want. It seems to work well and does what I needed.
Thanks for your input and I saved your example for future reference.
George
.
- Prev by Date: Re: IE7 Tooltip
- Next by Date: Re: IE7 - how to close a window in script
- Previous by thread: Re: IE7 Tooltip
- Next by thread: Re: IE7 - how to close a window in script
- Index(es):
Relevant Pages
|