How do I return a subset in jQuery plugin?
By default it's like this:
$.fn.ellipsis = function() {
...
return this.each(function(){
//do some operation on each element here to see if it qualifies
}
}
But now I want to return a subset of all, only those qu开发者_如何学JAVAalify in this.each(function() {})
,
how to modify the code so that it finally returns only those that qualify?
Check out jQuery's filter function: http://api.jquery.com/filter/
i would suggest using jquery.grep if your filtering mechanism is a function. makes it really easy to pull out just the items in the array that you need.
精彩评论