Resources:
Version one of the FAQ Page does not actually use JavaScript. However, it is included in this list to show the various ways to create a FAQ page. This page was created using named anchors (bookmarks). See Other Linking Options for more details on how to create them.
<title>FAQ_Beginner</title>
<link rel="stylesheet" href="FAQ_Beginner.css">
<li><a href="#dd1">When should I register?</a></li>
<dt id="dd1">When should I register?</dt>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</body>
<body>NOTE: The id attribute could have been added to the h1 element instead; however, it already had an id attribute but you can only have one id attribute per element.
<span id="#top"></span>
<h1 id="myHeading"> Frequently Asked Questions (Training) </h1>
<dt id="dd1">When should I register?</dt>NOTE: Notice the the "a" and "img" element are NESTED in the "dd" element.
<dd>You should register as soon as a class is available.
We make every attempt to have a minimum of two students
so you may be required to reschedule if the class does
not make. <a href="#top"><img src="images/top_Arrow.gif"
width="29" height="10" alt="top" /></a></dd>
Version two of the FAQ Page uses a simply JavaScript to allow Q/A to be toggled.
Disadvantage of the FAQ_Beginner.html:
Because it uses named anchors instead of JavaScript, if you have many questions and answers, it makes for a long page to scroll through.
Advantage of this version:
It reduces the height of the page by HIDING the answers and allowing a user to only UNHIDE the answer or answers that is needed while still minimizing the page height.
<title>FAQ_Intermediate</title>
<link rel="stylesheet" href="FAQ_Intermediate.css">
dl dd {
padding-top: 10px;
padding-bottom: 10px;
padding-left: 0px;
padding-right: 0px;
display: none;
}
<script>NOTE: This is a simple JavaScript that will TOGGLE the visibility of the answers on or off when they are clicked. The toggleElement function is passed the id from the question that is clicked, assigned to a variable to ascertain its style property (block or none) and then the "if" statement is used to check the current state of that display property and then switch it to the opposite state.
function toggleElement(elementID)
{
var targetElement = document.getElementById(elementID).style;
if (targetElement.display == "block")
{
targetElement.display = "none";
}
else
{
targetElement.display = "block";
}
}
</script> </head>
<dt><a href="#" onclick="toggleElement('dd1');">When should I register? </a></dt>
<dd id="dd1">You should register as soon as a class is available. We make every
attempt to have a minimum of two students so you may be required to reschedule
if the class does not make.</dd>
Version three of the FAQ Page uses a JAVASCRIPT FILE using a series of collapsible text that are all closed on start. Then, all of the FAQ answers can be opened or closed by clicking on them or clicking on the Open All or Close All button.
View FAQ_Advanced
<title>FAQ_Advanced</title>
<link rel="stylesheet" href="ToggleDL.css">
<link rel="stylesheet" href="ToggleDL.css">NOTE: This is a a more complex JavaScript that will TOGGLE the visibility of the answers on or off when they are clicked or when the Open All and Close All button is clicked.
<script type="text/javascript" src="ToggleDL.js"></script>
<body onload="ToggleDL()">
<h1 id="myHeading"> Frequently Asked Questions (Training)</h1>
<p>Click link next to <img src="images/toggleDLplus.gif" width="20" height="20" alt="" />
icon to view an answer. Click again to hide.</p>
<div>
<button href="#" id="OpenAll">Open All</button>
<button href="#" id="CloseAll">Close All</button>
</div>
<dl id="DL">
<dt>When should I register? </dt>
<dd id="dd1">You should register as soon as a class is available. We make every
attempt to have a minimum of two students so you may be required to reschedule
if the class does not make.</dd>
<dt>What are the class hours?</dt>
<dd id="dd2">Class time is 9:00am - 4:00pm. Two 10-15 minutes breaks are scheduled
in the morning and afternoon. Lunch is typically scheduled around noon. Students
can go out to eat or bring their own lunch.</dd>
<dl id="DL">
<dt>When should I register? </dt>
<dd id="dd1">You should register as soon as a class is available. We make every attempt
to have a minimum of two students so you may be required to reschedule if the class does
not make.</dd>
...
<div>
<button href="#" id="OpenAll">Open All</button>
<button href="#" id="CloseAll">Close All</button>
</div>
<dl id="DL">
<dt>When should I register? </dt>
and notice there is no plus icon image next to each question:
However, if you view the page in
a BROWER, press F12, and view the content of the Inspector panel, you will see the "a" element and a host of attributes INJECTED into the page.
NOTE: Notice the doToggleDL(0) function with the onclick handler. This function will be explained later.
SPECIAL NOTE: Notice that you can see the answer text in the "dd" text above; however, in the actually page it is hidden (see screenshot below). This is because the text is actually hidden from view using the following CSS selector:
#DL dd, .hideDD {
top: -9999px;
position: absolute
}
and notice there is a plus icon image next to each question:
Version four of the FAQ Page uses the BOOTSTRAP FRAMEWORK to create a series of collapsible accordions and a set of buttons to open and close all of the panels at one time.
IMPORTANT NOTE: While the Bootstrap Components in the Insert Panel could have been used for this tutorial, it is best to get the later version of the BootStrap framework components directly from the BootStrap website to avoid all of the compatibility issues that you may have with using an older version using Dreamweaver.
<title>FAQ_Expert</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk"
crossorigin="anonymous">
<link rel="stylesheet" href="FAQ_Expert.css">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity=
"sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"
integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
crossorigin="anonymous"></script>
</body>
NOTE: The first script is jquery.min.js, the second is popper.min.js, and the third is bootstrap.min.js. The "min" in the script names denotes that that are MINIFIED VERSIONS of the script files.
<h1 id="myHeading">Frequently Asked Questions (Training)</h1>
<div class="container-fluid">
</div>
NOTE: The div element that was added has a class of container-fluid that is part of the BootStrap framework. Typically, most content in a BootStrap framework is "contained" with a container class (e.g., container-fluid).
<div class="container-fluid">
<div class="accordion" id="accordionExample">
<div class="card">
<div class="card-header" id="headingOne">
<h2 class="mb-0">
<button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse"
data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Collapsible Group Item #1
</button>
</h2>
</div> <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
<div class="card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.
3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck
</div>
</div>
</div>
</div>
</div>
<div id="collapseOne" class="collapse hide" aria-labelledby="headingOne" data-parent="#accordionExample">
<div class="card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.
3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck
</div>
</div>
<div class="container-fluid">
<button class="btn btn-warning" id="toggleAccordions-show">Show All Answers</button>
<button class="btn btn-warning" id="toggleAccordions-hide">Hide All Answers</button>
<br>
<br>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>NOTE: This script basically toggle the panels on and off.
<script>
$(document).ready(function(){
/* The accordion is built so only one panel can be shown at the time,
so the key is to override this behavior by first removing the data-parent
attribute on SHOW and adding it on HIDE. */
$('#toggleAccordions-show').on('click', function(e) {
$('#accordionExample .collapse').removeAttr("data-parent");
$('#accordionExample .collapse').collapse('show');
})
$('#toggleAccordions-hide').on('click', function(e) {
$('#accordionExample .collapse').attr("data-parent","#accordion");
$('#accordionExample .collapse').collapse('hide');
})
});
</script>
<style>
.card-header{padding:0}
</style>
</head>
<div class="card">
<div class="card-header" id="headingFour">
<h2 class="mb-0">
<button class="btn btn-link btn-block text-left collapsed" type="button" data-toggle="collapse"
data-target="#collapseFour" aria-expanded="false" aria-controls="collapseFour">
Collapsible Group Item #4
</button>
</h2>
</div>
<div id="collapseFour" class="collapse" aria-labelledby="headingFour" data-parent="#accordionExample">
<div class="card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid.
3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck
</div>
</div>
</div>