Tuesday, June 2, 2009

[jQuery] slideDown()/slideUp width errors

Hello,

I am new to jQuery and already I'm seeing problems with the built in
slideDown()/slideUp() animations. I'm using a flexible width <table>
element, and when I use the function, the element does not return to
it's full width. I am thinking this has something to do with the way
jQuery finds the width of the element. Below is the html for the page:

<div id="archive">
<h2 class="first open">May</h2>
<table width="100%" cellspacing="0" cellpadding="0" border="0"
class="list">
<tr class="first">
<td width="65%"><a href="#">This month</a></td>
<td align="right">Sunday, May 31 <input type="button"
value="Edit"/></td>
</tr>
</table>
</div>


And the Javascript:

// Enable month names to re-open divs
$("#archive h2").not(":last").wrapInner("<a href='#'></a>").end().find
("a").click(function(event){

event.preventDefault();

var h2 = $(this).parent();

if (h2.hasClass("open")) { // Close

h2.removeClass("open");
h2.next().slideUp("fast");


} else { // Open

h2.addClass("open");
h2.next().slideDown("fast");


}

});


Any help would be appreciated.

Thanks,
Brendan

No comments: