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
});
1

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.