Home arrow HTML arrow Page 3 - More Convenient FAQ Web Pages
HTML

More Convenient FAQ Web Pages


A conventional Frequently Asked Questions page has questions at the top of the page. Below these questions are the answers. The questions are links. When you click a question the page jumps to the answer. We can design a better FAQ page, however. Keep reading to find out how.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
April 29, 2009
TABLE OF CONTENTS:
  1. · More Convenient FAQ Web Pages
  2. · Example
  3. · The HEAD Element
  4. · Testing with Browsers

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
More Convenient FAQ Web Pages - The HEAD Element
(Page 3 of 4 )

This is the code for the HEAD element:


<head>

<style type="text/css">

dt.faq {color:red}

dt.faq:hover {cursor:default}

dd.faq {color:brown}

dd.faq:hover {cursor:text}

</style>


<script type="text/javascript">

var oldID;


function expandorCollapse(ID)

{

//Change the color of the clicked DT element to orange

document.getElementById(ID).style.color = "orange";


//form the ID of its DD element

//extract the number part first

num = ID.substr(2);

ddID = 'dd' + num;


if (document.getElementById(ddID).style.display == "block")

document.getElementById(ddID).style.display = "none";

else

{

if (oldID)

{

document.getElementById(oldID).style.display = "none";

}

document.getElementById(ddID).style.display = "block";

}


oldID = ddID;

}

</script>

</head>


As you can see, the HEAD element has the style sheet and the JavaScript. We look at the style sheet first.

The first statement in the style sheet indicates that every DT element (question) has a text color of red. All the DL elements belong to the "faq" class. What actually determines the style of an element is a combination of the selectors and the declaration block in a CSS statement. The second statement has the hover selector for the DT elements. As you can see, as the mouse pointer goes over a DT element it takes the default shape. For most browsers, this is an arrowhead. The next statement indicates that the text color for any DD element (answer) is brown. The last statement indicates that when the mouse pointer goes over any DD element, it should be an I-bar.

Let us now look at the JavaScript. It begins with a variable, oldID. We shall see the use of this variable shortly. Next, you have the expandorCollapse(ID) function. When you click a question (DT element), this function is called, with the ID of the DT element passed as an argument. The function uses this ID to do what I have not yet explained. 

Remember that when a question is clicked, the color of its text has to become orange, permanently. The first statement in the function does this. Each ID begins with two letters followed by a number. The next statement extracts the number part of the ID and assigns it to the num variable. The number part of the ID of the DT element and its corresponding DD element are the same. The statement after that, forms the ID of the DD element corresponding (below) to the DT element.

You now have an if-else statement. Remember that when a question is clicked, any answer that was displayed has to go off; then the new answer has to be displayed. If the new answer was already displayed, it goes off (so clicking a question twice displays an answer and removes it as well). The if-statement checks to see if the answer for the question is already displayed (block); if it is, it removes it (none). The else part of the function has two sections. Before we look at the two sections, let us look at the last statement in the function.

The last statement in the function is:


oldID = ddID;


This statement assigns the ID of the current DD element (answer) to the oldID variable. If the oldID variable or any other variable is assigned a value, then it is equivalent to a logical true; otherwise, it is equivalent to a logical false. Let us now look at the else-part of the above if-statement. The first section checks to see if oldID is true. If it is true, it means that it had just been previously assigned; it means that its DT (question) had been clicked; it means that its answer is being displayed; it means that its answer has to be removed. The statement of the if-bock in the section does that.

Whether you removed a previously-displayed answer or not, you have to display the answer for the question that has been clicked. The second section of the else-part has just one statement, which does this. That is it for the function.


blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials