While using the selector input[id=value]
is technically right (because of the jQuery attribute selector), it isn't necessary. The main reason is because you're targeting an element by ID. Javascript has a special method that is especially fast, which I'm sure jQuery uses internally ( document.getElementById
) when you specify you're selecting by ID. To trigger the selection of an element by ID, you can use the #
character at the beginning of the selector string. Since you are trying to use the value of a variable as well, you can concatenate "#"
and vRow
, like:
$("#" + vRow).val(data);
#
is the equivalent of matching an element by ID. If you look at the jQuery selectors page ( http://api.jquery.com/category/selectors ), you'll see there are several special characters to help with selecting elements. As I said, #
is for ID....
is for class, etc. So instead of having jQuery parse the string "input[id=value]" and do a lot of extra processing, you can help jQuery do it more efficiently by simply using #
.