Reputation: 35213
$.each(data, function (i, val) {
if ($('input:text').hasClass(i)) {
$('.' + i).val(val);
}
It works, but im not a big fan of the $('.' + i).val(val);
. Must be a smarter way than combining strings using jquery, right?
Upvotes: 1
Views: 47
Reputation: 38318
Build selectors via string concatenation isn't a big deal. However using two selectors when one will work is wasteful:
$.each(data, function(i, val) {
$('INPUT.' + i).val(val);
});
Upvotes: 1
Reputation: 17739
We use similar to that to describe classes. You could combine the two:
$("input:text ." + i).val(val);
Upvotes: 0