1

Do you know how to instantiate JQuery UI widget by string?

Let's illustrate it with some sample code. Given the html link element below:

<a id="testLink" href="#">Test Link</a>

Normally, we can make it into button using code below:

$('#testLink').button();

What if I want to instantiate the button with string, for example:

var widget='button';
$('#testLink').[widget]();

Of course the code block above is not working (It is just for illustration purpose only), otherwise you will not see this question.

Please advice.

Thanks,

Chee Kin

1 Answer 1

5

You don't need the dot when you're using the [] accessor. This should work:

var widget='button';
$('#testLink')[widget]();
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.