Skip to content

Adds if(), else() and fi() to jQuery objects that can be used in chained function calls

License

Notifications You must be signed in to change notification settings

veloek/jquery.if-else

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jquery.if-else

When using chained function calls in jQuery, it happens that you only want some of the functions to be called under specific conditions. With this plugin, you can use if(), else(), elif() and fi() to accomplish this.

Ex.

$(mySelector)
  .css("color", "blue")
  .if(someCondition)
    .css("background", "red")
  .else()
    .css("background", "orange")
  .fi()
  .css("font-size", "22px");

The plugin also supports nesting of if conditions:

$(mySelector)
  .css("color", "blue")
  .if(someCondition)
    .css("background", "red")
    .if(anotherCondition)
      .text("Yep")
    .else()
      .text("Nop")
    .fi()
  .else()
    .css("background", "orange")
  .fi()
  .css("font-size", "22px");

Enjoy!

About

Adds if(), else() and fi() to jQuery objects that can be used in chained function calls

Resources

License

Stars

Watchers

Forks

Packages

No packages published