I want to send array into eq function as parameter. Like that:
$(this).find('tr').not(':eq(array)').each(function(){
});
I did this with using a loop and eval function but it doesn’t look easy editable. This is my code.
$.fn.grilestir = function(options){
var nots = '';
for(var i=0;i<options.row_numbers.length;i++){
nots += "not(':eq("+options.row_numbers[i]+")').";
}
eval("$(this).find('tr')."+nots+"each(function(){\
var tr = $(this); var orj;\
if(options.mod == 'passive-rows'){\
$(this).mouseover(function(){\
orj = tr.css('backgroundColor');\
tr.css('backgroundColor', '#777777');\
});\
$(this).mouseout(function(){\
tr.css('backgroundColor', orj); \
});\
}\
});");
}
Is there any way to do this?
I am assuming that your array contains a set of numbers that represent element indexes. The
eqselector will not work with that.You could use
filterto reduce the matched set of elements to those at indexes within your array:Here’s a working example.
Note the use of
Array.prototype.indexOf, which is not available in older browsers (notable IE < version 9). However, there are plenty of shims available to solve that problem. Or, as noted in the comments (thanks @mcgrailm), you could usejQuery.inArray: