I’m trying to use jQuery to filter a table on a page. I would like to fade out the currently displayed rows and fade in the rows matching the new selection. My jQuery code looks like this:
$('#details-table tr').hide();
var previousFilterResult = $();
var selects = $('#search-panel > select');
selects.change(function () {
selects.attr('disabled', 'disabled');
var filterResult = filterTable();
previousFilterResult.hide('slow', function () {
filterResult.fadeIn('slow', function () {
selects.removeAttr('disabled');
});
});
previousFilterResult = filterResult;
});
My problem is that when I initialize previousFilterResult with $() the code does not work as it never seems to hit the callback for the previousFilterResult.hide call. If I put a dummy div in the page and initialize previousFilterResult with $(‘#dummyDiv’) it works fine.
Is there any way I can initialize previousFilterResult without putting a dummy div on the page so that the above code still works?
Thanks.
No, you can’t.
From the documentation :
But you can easily change your code to
This is cleaner than using
$()which feel like a hack in my opinion.