I\'m trying to remove blank spaces from the begining and ending of inputs in general without adding a class or id or event
I tried this live demo but is using
try $.trim
on change
input with type text:-
jQuery
$(function(){
$('input[type="text"]').change(function(){
this.value = $.trim(this.value);
});
});
Search1:
Search2:
Search3:
Search4:
Search5:
Vanilla
window.onload = function() {
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'text') {
inputs[i].onchange = function() {
this.value = this.value.replace(/^\s+/, '').replace(/\s+$/, '');
};
}
}
}
Search1:
Search2:
Search3:
Search4:
Search5: