Alex Rivera | Logout

JQuery select a variable by passing a text string of its name

Asked 2011-04-12T19:51:56.097
11

I'd like to use a JQuery selector to return a variable by passing a text string of the variable name:

ex.

var test = "xxx";

I'm thinking I could do something like this, but it won't work:

  alert($("#test"));

Edit: People are getting confused. Think of it as a reflective way to get the contents of var test. Preferrably with a JQuery selector, but I'll take any way one can come up with it..

Edit
Report

1 Answer

1

Not sure, but maybe you are looking for eval function.

answered 2011-04-12T19:57:28.823

Your Answer