need an HTML table of contents which can be turned on or off by the user

I'd like a table of contents and considered using an entire pane on one side, but it took up to much room.

Any suggestions about how to keep the functionality of a table of contents but have it be an option to the user?

thanks,
newbieweb
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
sundaramkumarCommented:
a working sample is below
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>welcome</TITLE>
<script language="javascript">
function Toggle(){
   var tocStyle = document.getElementById('toc').style;
   if(tocStyle.display=='none')tocStyle.display='block';
   else if(tocStyle.display='block')tocStyle.display='none';
}

</script></HEAD>

<BODY>
<div style="float:right"><a href="#" onclick="javascript: Toggle()">Table of Contents</a></div>
<br/><br/>
<p>
blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
</p>
<br/><br/>
<p>
blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
</p>
<br/><br/>
<p>
blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
</p>
<br/><br/>
<p>
blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah
</p>
<div id="toc" style="position:absolute;width:150px;height:100px;top:50px;left:1px;display:none;Z-index:10;background-color:#FFFFFF;-moz-opacity:0.90;filter:alpha(opacity=90,finishopacity=90);border:1px #a1bcdf solid">
<li>1.Index</li>
<li>2.Intro</li>
<li>3.How to</li>
<li>4.Conclusion</li>
<li>5.Bibliography</li>
</div>
</BODY>
</HTML>
0
 
sundaramkumarCommented:
add a style to the table of contents div/ table

as <div id="toc" style="display:none">
....
....
...

</div>

Now add a button/small image for table of contents
<img src="yourimage" onclick="showToc()">

add javascript fn

function showToc()
{
 if(document.getElementById('toc').style.display=='none')
  document.getElementById('toc').style.display='block';
 else
  document.getElementById('toc').style.display='none'
}
0
 
sundaramkumarCommented:
So whenever the image is clicked the toc will shown if it is hidden. if the image is clicked again the toc will hide.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.