Selecting / operating on multiple elements
Hi All,
I am creating an FAQ type page with rows of questions that will drop down the respective answer when clicked. I have it mostly working, except I can't find a way to close all answers before opening the next one. I have tried everything I can think of (or search), but to no avail. I am using the following code, where QQQ1/2 are the questions, and AAA1/2 are the answer divs:
- //Question/Answer
- $(".QQQ1,.QQQ2").click(function () {
- // check the visibility of the next element in the DOM
- if ($(this).next().is(":hidden")) {
- $(this).next().slideDown("fast"); // slide it down
- } else {
- $(this).next().hide("fast"); // hide it
- }
- });
-
- $(".AAA1,.AAA2").click(function () {
- $(this).hide("fast"); // hide it
- });
On that note, I found this code in the jQuery tutorials which claims better performance for this application, but like everything else I can't get it working.
$('#faq').find('dd').hide().end().find('dt').click(function() { $(this).next().slideToggle()
Any suggestions to resolving my woes, or even a push in the right direction would be greatly appreciated!
Thanks