Isaac Lubow
Isaac Lubow

Reputation: 3573

How can I pass a variable and a string into the same jQuery selector?

I have the following:

var x = '.'+this.id;  

and this does not work:

$(x,'#thumb').show();

but this does:

$(x).show();

and obviously so does this:

$('#thumb').show();

What am I missing? Should I be doing something else in general to pass variables (even on their own) through jQuery?

Upvotes: 1

Views: 2709

Answers (1)

Jeevan Takhar
Jeevan Takhar

Reputation: 491

You need to concatenate the two strings together:

$(x+',#thumb').show();

Upvotes: 2

Related Questions