0

This is the concept. what is the possible way to do this
Here my code:

var animationName='slideUp';
if(true){
animationName='fadeOut';
}

$('.className').animationName(200,function(){
     //callback
});
Manoj Kumar
  • 63
  • 1
  • 4
  • 1
    Possible duplicate of [calling a jQuery function named in a variable](http://stackoverflow.com/questions/8588307/calling-a-jquery-function-named-in-a-variable) Hope this link will help you. – technico Aug 07 '16 at 13:58

1 Answers1

0

You can use eval() to execute string as javascript expression. In eval() you can use variable as function name.

var animationName = "slideUp";
eval("$('div')."+ animationName +"(200, function(){})");
div {
    width: 50px;
    height: 200px;
    background: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>
Mohammad
  • 21,175
  • 15
  • 55
  • 84