Reputation: 424
JQuery allow to use function as .filter() argument to test each element in the set
$( "li" )
.filter(function( index ) {
return (index > 3) && (index < 10);
})
.css( "background-color", "red" );
how I can to pass arguments to this function so it looks like
$( "li" )
.filter(function( index, min, max ) {
return (index > min) && (index < max);
})
.css( "background-color", "red" );
Upvotes: 2
Views: 2400
Reputation: 30557
Declaring the variables before calling filter should work just fine
var min = 3, max = 19;
$( "li" )
.filter(function( index ) {
return (index > min) && (index < max);
})
.css( "background-color", "red" );
There is no need to pass in arguments in this case.
Upvotes: 8