6

I need to call a function in the following fashion:

var f = 'fadeOut';
$(v).f(s, function(){
    $(v).css('visibility', 'hidden').css('position', 'absolute');
});

Is this possible to do simply?

2

1 Answer 1

8

Yes

var f = 'fadeOut';
$(v)[f](s, function(){
    $(v).css('visibility', 'hidden').css('position', 'absolute');
});
Sign up to request clarification or add additional context in comments.

2 Comments

Any property of an object can be accessed with dot-syntax or square brackets. The latter though the only way to use if the property contains spaces or other disallowed characters
@BorisShemigon You are correct, however you cannot access a property with dot syntax via a string variable, in that case you must use brackets or utilize eval which I do not recommend.

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.