User123 User123 - 2 months ago 7
jQuery Question

JQuery - Filtering elements by attribute in jquery each

I'm trying to push data-type value of all visible rows into an array how do I do it using jquery?

I did something like this but I'm pretty sure its incorrect as its not working.

var myArray = [];

$('#myTableId tbody tr').each(function() {
myArray.push($(this).not('.class="hidden"').data('type'));
});

Answer

use map() and use not() before looping

var myArray =  $('#myTableId tbody tr').not('.hidden').map(function(){
   return $(this).data('type')
}).get();

You could do same with $.each also...the not() would remain the same

Comments