This code (http://jsbin.com/isexez/5/edit) functions as expected: (1) it displays the page selected; and (2) it highlights the number of the selected page.
I would appreciate help in improving it.
I am in the process of writing an ebook (http://www.keepcount.net/ebook/01-09/02_tricks.html) and need to improve this code before I get back to my writing.
* Here's my jQuery code as suggested by @Gisborne *
See also jsbin.com/iduxol/2/edit
<!DOCTYPE html>
<html>
<head>
<!-- Need to add http: to link in following line -->
<script class="jsbin" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> -->
<meta charset=utf-8 />
<title>JS Bin</title>
<style>
.nodisp { display:none; }
.highlight { background:yellow; }
</style>
</head>
<body>
<!-- When page numbers (p1 & p2) are clicked, page's text is displayed and page number remains highlighted -->
<span class="pageNumbers">
<a id="1"> p1 </a>
<a id="2"> p2 </a>
</span>
<!-- Show page 1 initially -->
<div id="pg1" class="page">
text on page 1
</div>
<!-- Hide page 2 initially -->
<div id="pg2" class="page nodisp">
quiz on page 2
</div>
<script>
$("span.pageNumbers a").click(function () {
// Remove all highlighting
$("span.pageNumbers a").removeClass("highlight");
// Add highlighting to clicked page number
$(this).addClass("highlight");
// Hide all text
$("div.page").hide();
// Show text corresponding to clicked page number
$("#pg"+ $(this).attr('id')).show();
});
</script>
</body>
</html>