$
(
document
)
.
ready
(
function
(
)
{
function
MyAccordion
(
)
{
// Hide the text containers
$
(
'dl.accordion dd'
)
.
hide
(
)
;
// Insert a span with the class of "arrow" in every dt
$
(
'dl.accordion dt'
)
.
append
(
'<span class="arrow"></span>'
)
;
// Add the class "active" to the first header and display the text bellow it
$('dl.accordion dt:first').addClass('active').nextUntil('dt').show();
// Upon clicking a dt element
$
(
'dl.accordion dt'
)
.
click
(
function
(
)
{
// A) if it has class "active", do:
if
(
$
(
this
)
.
hasClass
(
"active"
)
)
{
// 1) Hide the text bellow it
$
(
this
)
.
nextUntil
(
'dt'
)
.
slideUp
(
250
)
;
// 2) Remove its "active" class
$
(
this
)
.
removeClass
(
'active'
)
;
}
// B) If it does not have the class "active", do:
else
{
// 1) Show the text bellow it
$
(
this
)
.
nextUntil
(
'dt'
)
.
slideDown
(
250
)
;
// 2) Hide the text bellow every other dt tag
$(this).siblings('dt').nextUntil('dt').slideUp(250);
// 3) Add the class "active" to it
$
(
this
)
.
addClass
(
'active'
)
;
// 4) Remove the class "active" from any other dt element
$
(
'dl.accordion dt'
)
.
not
(
this
)
.
removeClass
(
'active'
)
;
}
}
)
;
}
MyAccordion
(
)
;
}
)
;