It is the on/off behaviour that means you'll need JavaScript, more than the click. (The click is possible to work with using :visited (pseudo-class) and the + selector).
The typical JavaScript thing to do is to have the CSS define two classes for this purpose and do something like:
Code:
var toggleOn="toggleOn"; // class name used in CSS for active/visible style
var toggleOff="toggleOff"; // class name used in CSS for hidden style
function toggleButton(elementId) {
var elem=document.getElementById(elementId); // find the element to toggle on/off
if(elem !=null) { // do not do anything unless the element actually exists
if(elem.className.indexOf(toggleOn) == -1) { // if class name does not contain the toggleOn name
elem.className.replace(toggleOff,toggleOn);
}
else {
elem.className.replace(toggleOn,toggleOff);
}
}
return false; // do not let the event bubble up any further, in case of hyperlinks this prevents the browser from changing address
}
Then in HTML something like
Code:
<a href="#someValidIdHere" onclick="javascript:toggleButton('elementToToggle');">Button</a>
<p id="elementToToggle">Content content content</p>
In CSS:
Code:
.toggleOn {
/* styles to make elements appear visible, I simply swap background & foreground instead */
background: #cccccc;
color: #dedede;
}
.toggleOff {
/* styles to make elements appear hidden, I simply swap background & foreground instead */
color: #cccccc;
background: #dedede;
}
Bookmarks