Reputation: 5488
I have the following jQuery code:
$(myObj).val( $.trim($(myObj).val()) );
From my experience with jQuery and it's elegant approach to common scripting tasks I feel like jQuery should provide a more elegant way to trim an objects value data. Is there a more elegant way in which the object is not called twice?
Upvotes: 2
Views: 297
Reputation: 13495
Assign it to a variable.
var a = $(myObj);
a.val($.trim(a.val()));
Upvotes: 0
Reputation: 22268
$(myObj).val(function(i, val){
return $.trim(val);
});
See this example from the jQuery val
docs.
Upvotes: 4