jQuery call function from a string [duplicate]

You can use the bracket notation to access the member with a string containing the identifier:

var target="next";
$("foobar")[target]();    // identical to $("foobar").next()

Leave a Comment