views:

34

answers:

3

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 qualify in this.each(function() {}),

how to modify the code so that it finally returns only those that qualify?

+2  A: 

Check out jQuery's filter function: http://api.jquery.com/filter/

inkedmn
How to do the operation and filter at the same time?
wamp
A: 

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.

nathan gonzalez
A: 
var acceptRate = parseInt($('.accept-rate').text())

    if (acceptRate > 90 ) {
       // I would do my best to help
    } else if (acceptRate > 70 ) {
       // of course I will still help
    } else if (acceptRate > 50 ) {
       // yeah, I can help...
    } else if (acceptRate > 40 ) {
       // hmmmm....
    } else if (acceptRate > 30 ) {
       // 50-50
    } else if (acceptRate > 20 ) {
       // I would care reading the problem... ONLY read..
    } else {
      // press browser back button
    } 

would you care?

Reigel