Hello! My name is Victor, I am a web developer at the University of Georgia School of Law. In case it is handy, my email address is: [email protected]
Big note: All of the choices I made were to make this work with the Drupal 7 CMS. We are in the process of upgrading to Drupal 8 as I write this.
Please get in touch if you need some help with any of this code here.
The Stylesheet code was written in SASS using the BEM methodology.
<h2>FAQ Section Name</h2>
<div class="faq-list">
<div class="faq-list__item">
<button class="faq-list__question">
This is the first question.
</button>
<div class="faq-list__answer">
<p>Oh, is this the first answer?</p>
<p>Well, things are looking up!</p>
</div>
</div>
<div class="faq-list__item">
<button class="faq-list__question">
Wow, a second question?
</button>
<div class="faq-list__answer">
<p>Sure, a second answer too!</p>
</div>
</div>
<div class="faq-list__item">
<button class="faq-list__question">
What about a third question?
</button>
<div class="faq-list__answer">
<p>How about a third answer?</p>
</div>
</div>
</div>
When it needs to be updated, the HTML is manually edited using Drupal 7's built-in content editor, ensuring that its text box is set to FULL HTML in order to keep the class names of the individual HTML elements. Drupal will strip them otherwise. Nothing fancy here. You'll notice I used button
elements for the questions, that's to ensure that keyboards can easily tab over to the question they want.
This is all just vanilla javascript, it uses ARIA attributes as a way to trigger the show and hide states of the answers, hopefully this also makes things nicer for those that are in need of accomidation. The actual showing and hiding of items is handled by the CSS.
So long as the faq.js
script is loaded after the page content is rendered (I added the script tag to the bottom of the Body tag, just before the closing </body>
tag in our template.) it will search the document for any elements on the page that have the class .faq-list__item
. if it finds any, it automatically sets up the show and hide logic that we need. If it doesn't find any, it does nothing.