The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

I din't run this code, it should work, but may contain some minor syntax errors.
How ir works. You call function show_comments(), pass link to the current element (which initiated an event) and array of elements to change state. Then you check if that array is not empty, change innerHTML of the element <a> (depending on the state of the first element in array) and then loop through all array and call function showHideEl.
It takes 1 parameter which can be element link or a string. If it is a string (like in our case), it gets element link for it and then changes state.

That's all. Simple and effective.

One disadvantage. if you have 2 elements, one is hiddent and other is visible, this approach will affect both and visible will be hidden and hidden will appear. So they flip states.

If it is undesirable, then you can write something like:

Code JavaScript:

var state =false;

in the beginning of the page and change functions in the following way:

Quick note. Don't use IDs thatbegin with digit. This should be like variable name - first is letter or _, after that any digits or letters or _. digits on the first place also work, but that is not "best practice"

I've been trying to expand the script a little by having the function change each of the div's innerHTML to display the correct link text. For example, if the Show All link is pressed, this will show all the divs. But their individual show/hide feature doesn't correlate to the way it is being displayed.