Show/Hide button (text) for Accordion

Posted by Kevin on Stack Overflow See other posts from Stack Overflow or by Kevin
Published on 2010-06-09T13:42:45Z Indexed on 2010/06/09 13:52 UTC
Read the original article Hit count: 294

Have an accordion with a "view" button to open close the accordion panel (using jQuery Tools), but I would like to have dynamic text that says "show/hide" depending on the state...

Here is the code for the accordion in asp.NET

<div id="accordion">
  <% foreach (var eventModel in ViewModel)
     { %>

     <% var isNewMonth = eventModel.Date.Month != previousMonth; %>

     <% if (isNewMonth && previousMonth > 0)
        { %></table></div><% } %>

     <% previousMonth = eventModel.Date.Month; %>

     <% if (isNewMonth)
        { %>
        <h2><%= string.Concat(eventModel.Date.ToString("MMMM"), " ", eventModel.Date.Year) %> <span style="float:right;"><a href="#" class="button blue small">View</a></span></h2>
        <div class="pane" style="display:block">
            <table id="listTable" width="100%" cellpadding="3" cellspacing="0" border="0"> 
            <tr align="left" valign="top"><th align="left" valign="top">Date</th><th align="left" valign="top">Event</th><th align="left" valign="top">Event Type</th></tr>
     <% } %>

            <tr align="left" valign="top"><td align="left" valign="top"><b><span id="date" style="float:left;"> <%= string.Concat(eventModel.Date.ToString("MMMM"), " ", eventModel.Date.Day, " </span><span id='day' style='float:left'>" + eventModel.Date.DayOfWeek + "</span> ")%></b></td><td align="left" valign="top" ><%= Html.ActionLink(eventModel.Name.Truncate(40), "event", "register", new { id = eventModel.Id }, null)%></td><td align="left" valign="top"><%= string.Concat(" ", eventModel.Sport)%></td></tr>

  <% } %>

  <% if (ViewModel.Count > 0)
     { %></table></div><% } %>
</div>

Here is the initialization script using jQuery:

 
$(function() { 
$("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: 0});
$(".small").click(function() { moveToTop(); });

});

 

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about accordion