| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

vietmusic_togglecontents2

This version was saved 17 years, 10 months ago View current version     Page history
Saved by PBworks
on May 10, 2006 at 9:16:51 am
 

Make an option to toggle contents on/off (Part 2)

 

by vietmusic

 


 

Method 2

 

The basic idea of the first content toggle was to wrap the <toc> in another div, and make that disappear. But if you've seen Wikipedia, you know that their toggle is embedded inside of the table. You can do that too, with some ingenuity.

 

Code

 

Just paste the following code into your wiki page, preferably at the bottom. Then, just put your Table of Contents with <toc> anywhere you want, and it'll automatically embed a toggle INSIDE of the contents. Furthermore, you can have as many <toc>'s as you want (a limitation of the other way is that there's just one per page).

 

<script language="javascript">
var allPageTags = new Array(); 
var allPageTags=document.getElementsByTagName("*");
for (i=0; i<allPageTags.length; i++) {
if (allPageTags[i].className=="toc")
allPageTags[i].innerHTML = "<a href="javascript:TOCToggle(" + i + ")"><b><small>Contents (Hide)</small></b></a>" + '<div id="toctog' + i + '">' + allPageTags[i].innerHTML + '</div>';
}
function TOCToggle(id_num) {
if (document.getElementById("toctog"+id_num).style.display == "none") {
    document.getElementById("toctog"+id_num).style.display = "block";
    allPageTags[id_num].innerHTML = allPageTags[id_num].innerHTML.replace("Contents (Show)","Contents (Hide)");
}
else {
    document.getElementById("toctog"+id_num).style.display = "none";
    allPageTags[id_num].innerHTML = allPageTags[id_num].innerHTML.replace("Contents (Hide)","Contents (Show)");
}
}
</script>

 

Example

 

See above.

 

 

Comments (0)

You don't have permission to comment on this page.