Reputation: 12213
I have a number of input boxes of class "inputbox". I'd like to append ".00" to the end of each of them. I tried this:
$('.inputbox').val($(this).val()+".00");
But the $(this) doesn't return any value, so I just get ".00" in all the boxes. Any help on how to get the value from each of those input boxes so I can add to it would be greatly appreciated.
Upvotes: 0
Views: 174
Reputation: 318182
val()
has a callback, you can use it for exactly things like this, where you need to concantenate to the values of many elements in a collection.
$('.inputbox').val(function(_, val) { return val + ".00" });
Upvotes: 1
Reputation: 919
jQuery selectors return arrays. But val()
function can not be used for arrays, it can be used for a single element. So you can use .each() of jQuery:
$('.inputbox').each(function(){
$(this).val($(this).val()+".00");
});
Upvotes: 0