views:

139

answers:

2

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(); });

});

 
A: 

You can use the toggle-Method: http://api.jquery.com/toggle/

gamue
Can you be more specific - I can select the link with .small but how do I select the text to change?
Kevin
should be something like this (sorry haven't tested it):$('.small').toggle(function() { $(this).text('show');}, function() { $(this).text('hide');});
gamue
A: 

Note if you didnt want to deal with alot of script you could use the icon option in the accordian and display an image that says show/hide.

look here

http://jqueryui.com/demos/accordion/#option-icons


Edited

For a show/Hide label on the tab when selected

$( "#accordian" ).tabs("#accordion div.pane", 
  {tabs: 'h2', 
  effect: 'slide', 
  initialIndex: 0
  select: function(event, ui) {
     //ui.panel is the current tab I think
     //you should be able to toggle a show/hide on each tab from here
  }
}
);
John Hartsock
I'm using jquery tools and initiliazing like this:$("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: 0});So how do I do that exactly?
Kevin
note you are just naming the element accordian. and not actually using the accordian. note the $("#accordian").tabs this is jquery ui tab control.
John Hartsock
right ok - so back to my original question... how can I rename the text?
Kevin
maybe using innerHTML?
Kevin
try $.text() or if you want to use html try $.html()
John Hartsock
ok, doing something like this:$(".small").click(function() { $(".small").html("Hide"); });How do I do a check to check it back to "Show" ?
Kevin
look at the tabs themselves when jquery creates the tabs use the classes it creates to get the unselected tabs. then change the text inside
John Hartsock