1

Possible Duplicate:
How to use javascript variables in jquery selectors

This works

$('input[name=nickname]').css(...);

Now how can I write the same but with variable ?

string[1]='nickname';
Community
  • 1
  • 1
David
  • 4,098
  • 13
  • 47
  • 87

2 Answers2

6

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(...);

Matt
  • 72,564
  • 26
  • 147
  • 178
3
$('input[name=' + var_that_holds_the_name + ']').css(...);
Marc B
  • 348,685
  • 41
  • 398
  • 480