Ryan Ryan - 1 year ago 67
jQuery Question

Is it possible to make a jquery selector take in a variable?

I have links dynamically displaying on a page, their IDs are also dynamically created.

Can I do something like this:


I've been trying different things like:

var whatever = "'#"+originalVariable+"'";


None of this is working. Is there a correct way to do this? Or is it just not possible?

When the user clicks a link, I want something like a check mark to display next to each link clicked. The problem as I said above, is these are all dynamically created, so I can't hard code anything in.

Answer Source


var whatever = "#"+originalVariable;

You want whatever to be a string equal to "#foo" not "'#foo'"

The outside quotes don't actually exist ... It's just a way to tell the parser you are describing a string.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download