Take the 2-minute tour ×

Possible Duplicate:
How to use javascript variables in jquery selectors

This works


Now how can I write the same but with variable ?

share|improve this question
add comment

marked as duplicate by Matt, locrizak, zzzzBov, pimvdb, Felix Kling Oct 21 '11 at 14:48


2 Answers

up vote 2 down vote accepted
$('input[name=' + var_that_holds_the_name + ']').css(...);
share|improve this answer
add comment

Simply use string concatenation:

$('input[name=' + string[1] + ']').css(...);

Although technically it should be both $('input[name="nickname"]').css(...); and $('input[name="' + string[1] + '"]').css(...);

share|improve this answer
add comment
