geting the html of tables with greater than 4 rows stored in an array map(function()

With the following code in jquery:

$(source).children('table').filter(function() { return ($('tbody > tr', 'table').length >= 4)})

I filter out tables that have 4 rows or greater. I'm trying to create an array of the html from this using the map (function() but this doesn't seem to work. Im trying to get the html() of each table that satisfies this condition.

-------------Problems Reply------------

I think this is what you're looking for:

$(source).children("table").map(function() {
if ($("tbody > tr", this).length >= 4) {
return $(this).html();
} else {
return null;

Selector context in jQuery expects a DOM element, jQuery, or document. Using this will restrict the query to the element being evaluated in the filter function.

var htmlArray = $('#source').children('table')
.filter(function() {
return ($('tbody > tr', $(this)).length >= 4);
}).map(function(i, item) {
return $(item).html();

You can do it all in the map()[docs] method.

var arr = $(source).children('table').map(function() {
if( $('tbody > tr', this).length >= 4 ) return $(this).html();

Or using the[docs] method.

var arr = $.map($(source).children('table'), function(val,i) {
if( $('tbody > tr', val).length >= 4 ) return $(this).html();

Category:jquery Views:0 Time:2011-06-21
Tags: jquery

Related post

Copyright (C), All Rights Reserved.

processed in 0.166 (s). 11 q(s)