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;
}
}).get();

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();
}).get();

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();
}).get();

Or using the jQuery.map()[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) dskims.com, All Rights Reserved.

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