I want to backup an html table to afterwards filter it using jquery:
$('.row').closest('td').not(':contains(' + v + ')').parent('tr').remove();
Since I do remove() I have to back up the rows before:
var allTable = $('#mytable').html();
And then, when filter is performed I turn back to previous table data:
$('#mytable').html($(allTable));
But this does not work. If I do:
alert($(allTable).filter('tr').length);
next to the first assignment, zero rows are returned.
Please, can you assist me?
filter()is used to find elements within an array of elements. This isn’t what you need. You’re looking tofind()the child elements within another. Also, storing the HTML only to turn it back in to a jQuery object is a little redundant – you may as well just store the jQuery object itself. Try this:Example fiddle