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,332
  • 13
  • 54
  • 93

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
  • 74,352
  • 26
  • 153
  • 180
3
$('input[name=' + var_that_holds_the_name + ']').css(...);
Marc B
  • 356,200
  • 43
  • 426
  • 500