Nathan S Nathan S - 1 year ago 63
Javascript Question

Collapsable table Javascript - changing initial view

I have a calendar that is made up of a

for each month. I am using Javascript to expand/collapse each month.


$(function() {
var $month = $('.month');



<table border="0" cellpadding="0" class="month jan">
<tr class="monthLabel">
<th scope="col" colspan="7">
<tr class="weekLabel">
<th class="sun" scope="col" abbr="Sunday">Sun</th>
<th class="mon" scope="col" abbr="Monday">Mon</th>

It works fine, but right now, it defaults with the first table (January) expanded, and the rest collapsed. I would like it to, instead, default to the current month expanded and the rest collapsed. Is there a way I can do this without completely reformatting the tables? This would be ideal, as there are about 40 of these calendars that are automatically generated using VBasic. If possible, I'd like the actual table HTML to remain unchanged.

Answer Source

I presume the reason it defaults to January is that you are firing the click event on the the first row (January) with -


If you would like to default to a different month, just supply a different row number -

// for february

Personally, I would extract the function out so it could be used outside a click event.

function showMonth( monthName ){ .... }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download