0

Trying to figure out a way to insert a condition in Jquery sequence of commands. Basically my point is I can save the code length.

Example:

var first=true;

if(first){
    ap.nextAll("div").first()....
}else{
    ap.nextAll("div").last()....
}

and whether it can do something like this:

ap.nextAll("div").(first?first():last())....

This is the only example I know that it could be solve : last, but it just as an example.

Thanks Pesulap

Pesulap
  • 884
  • 8
  • 19
  • I might describe enough, right? – Pesulap Jan 23 '14 at 08:13
  • possible duplicate of [call javascript object method with a variable](http://stackoverflow.com/questions/6737840/call-javascript-object-method-with-a-variable) – Barmar Jan 23 '14 at 08:16

1 Answers1

1

yes you can use bracket notation along with ternary operator

ap.nextAll("div")[first? 'first' : 'last']()....
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531