I'm using the script below to show/hide text in an FAQ format. For accessibility, this won't work. Those who navigate with a keyboard won't have a way to expand the text because the element you click on to expand/hide is a heading, not a link, and headings don't receive focus when tabbing through a page.
How would I change this script to have it show/hide when the user either clicks the link OR the link receives keyboard focus?
Any help would be greatly appreciated. I've been tinkering with this and can't seem to get it.
Script:
<script type="text/javascript">
if (document.images) {
img1 = new Image();
img1.src = "/images/expand-symbol.jpg";
img2 = new Image();
img2.src = "/images/collapse-symbol.jpg";
}
$(document).ready(function () {
$('.section').hide();
$('h3').click(function () {
$(this).toggleClass("open");
$(this).next().toggle();
}); //end toggle
}); //end ready
</script>
HTML:
<h3 class="question">Question that is always shown</h3>
<div class="section">
<p>Text that appears when you click the question</p>
</div>