Aishwarya L Aishwarya L - 1 year ago 60
Javascript Question

Expanding and collapsing table rows in jQuery

Here is the

jQuery code
expanding and collapsing the rows in a table
but it just doesn't seem to work. Am I going wrong anywhere ?

$('.Complex').click(function() {
if ($(this).hasClass("collapsed")) {
.find('td > div')
.slideDown("fast", function() {
var $set = $(this);
} else {
.wrapInner('<div style="display: block;" />')
.find('td > div')

The following is the jsFiddle

Answer Source

You have over complicate it. Simply use $.fn.toggleClass() and $.fn.toggle()

$('.Complex').click(function () {


If you want sliding motion then use $.fn.slideToggle() instead of $.fn.toggle()

Display or hide the matched elements with a sliding motion.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download