Aishwarya L Aishwarya L - 5 months ago 9x
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


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.