Help with expanding/collapsing table rows
Hello all,
I have a table with rows than can be expanded/collapsed by clicking on a +/- button. Initially, all the child table rows are collapsed.
To give you some insight, this is a FAQ page, with several headings. Someone may link (via an anchor) to a particular heading on this page. What I would like to do, is have this table row expand (visible) if it was linked to via an achor.
How I think this will work is when a anchor/link on page 1 is clicked, its ID is stored an passed to page 2 (somehow). On page load, page 2 will check the ID that was passed to it, and will open all children rows with the same ID... I may be completely wrong, but if anyone has any suggestions/can tell me how to do this, that would be great. My code for the FAQ page with the collapsable/expandable tables is bellow:
JS:
- <<script type="text/javascript" src="page_support/jquery.js"></script>
- <<script type="text/javascript">
- <$(document).ready(function() {
- var toggleMinus = 'page_support/bullet_toggle_minus.png'
- var togglePlus = 'page_support/bullet_toggle_plus.png'
- var $subHead = $('tbody th:first-child')
- $subHead.prepend('<img src="' + toggleMinus + '"alt="Click to expand/collapse" />')
- $('img', $subHead).addClass('clickable')
- .click(function() {
- var toggleSrc = $(this).attr('src')
- if ( toggleSrc == toggleMinus ) {
- $(this).attr('src', togglePlus)
- .parents('tr').siblings().fadeOut('fast')
- } else{
- $(this).attr('src', toggleMinus)
- .parents('tr').siblings().fadeIn('fast')
- }
- })
- })
- </script>
THANKS :D