Hey everyone, so i am still pretty lost with jquery and I'm trying to get this accordion script working with a table rather than an unordered list.
heres the function.
heres the table.
So basically, I want to rows designated as 'messageHead' to always be visible. and for the accordian to work with the messageBodies.
How can I alter this script to work this way with the table. I think it has something to do with how .next() works. but I'm not sure.
Thanks for the help!
heres the function.
Code:
function initMenu() {
$('#inbox tr.messageBody').hide();
$('#inbox tr messageBody:first').show();
$('#inbox tr. messageHead a').click(
function() {
var checkElement = $(this).next();
if((checkElement.is('tr.messageBody')) && (checkElement.is(':visible'))) {
return false;
}
if((checkElement.is('tr.messageBody')) && (!checkElement.is(':visible'))) {
$('#inbox tr.messageBody:visible').slideUp('slow');
checkElement.slideDown('slow');
return false;
}
});
}
heres the table.
HTML:
<table id="inbox">
<tr>
<th>From:</th>
<th>Subject:</th>
<th class="date">Sent:</th>
</tr>
<tr class="messagehead">
<td><a href="#">Sender</a></td>
<td><a href="#">Subject</a></td>
<td class="date">Date</td>
</tr>
<tr class="messageBody">
<td colspan="3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel risus. Aenean sollicitudin turpis. Quisque eu massa aliquam mi sodales tempor. Mauris scelerisque nisl at nulla. Sed posuere cursus turpis. Mauris pharetra faucibus nunc. Proin vulputate mauris non nulla. Praesent eget metus. Integer sapien sapien, commodo nec, volutpat quis, eleifend eu, neque. Integer non nulla. Aenean dapibus, libero vitae ullamcorper dictum, dolor sapien volutpat magna, eu interdum mi ipsum vel nunc. Maecenas aliquet mollis nisi. Aenean massa eros, lobortis vel, facilisis id, vulputate sit amet, dui. Praesent eleifend dui a ipsum. Phasellus convallis sapien sit amet erat. Praesent felis. Vivamus malesuada eros.
</td>
</tr>
<tr class="messagehead">
<td><a href="#">Sender</a></td>
<td><a href="#">Subject</a></td>
<td class="date">Date</td>
</tr>
<tr class="messageBody">
<td colspan="3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel risus. Aenean sollicitudin turpis. Quisque eu massa aliquam mi sodales tempor. Mauris scelerisque nisl at nulla. Sed posuere cursus turpis. Mauris pharetra faucibus nunc. Proin vulputate mauris non nulla. Praesent eget metus. Integer sapien sapien, commodo nec, volutpat quis, eleifend eu, neque. Integer non nulla. Aenean dapibus, libero vitae ullamcorper dictum, dolor sapien volutpat magna, eu interdum mi ipsum vel nunc. Maecenas aliquet mollis nisi. Aenean massa eros, lobortis vel, facilisis id, vulputate sit amet, dui. Praesent eleifend dui a ipsum. Phasellus convallis sapien sit amet erat. Praesent felis. Vivamus malesuada eros.
</td>
</tr>
<tr class="messagehead">
<td><a href="#">Sender</a></td>
<td><a href="#">Subject</a></td>
<td class="date">Date</td>
</tr>
<tr class="messageBody">
<td colspan="3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel risus. Aenean sollicitudin turpis. Quisque eu massa aliquam mi sodales tempor. Mauris scelerisque nisl at nulla. Sed posuere cursus turpis. Mauris pharetra faucibus nunc. Proin vulputate mauris non nulla. Praesent eget metus. Integer sapien sapien, commodo nec, volutpat quis, eleifend eu, neque. Integer non nulla. Aenean dapibus, libero vitae ullamcorper dictum, dolor sapien volutpat magna, eu interdum mi ipsum vel nunc. Maecenas aliquet mollis nisi. Aenean massa eros, lobortis vel, facilisis id, vulputate sit amet, dui. Praesent eleifend dui a ipsum. Phasellus convallis sapien sit amet erat. Praesent felis. Vivamus malesuada eros.
</td>
</tr>
</table>
So basically, I want to rows designated as 'messageHead' to always be visible. and for the accordian to work with the messageBodies.
How can I alter this script to work this way with the table. I think it has something to do with how .next() works. but I'm not sure.
Thanks for the help!