John
John

Reputation: 1594

Is it possible to name a jquery selector the value of a variable

For example, if i had a variable in javascript

 var nombre;
 onclick="nombre='someValue'"

and somewhere along in my code this javascript variable's value is changed like above, could I set the value of that variable to be the class name in the jquery selector so it would be like

$('.someValue').show()

Upvotes: 2

Views: 68

Answers (1)

Blaster
Blaster

Reputation: 9080

Yes you can:

$('.' + nombre).show();

This assumes that your variable nombre has such scope that it is available in your jQuery code too.

Upvotes: 4

Related Questions