Ch Hong Ch Hong - 23 days ago 6
Javascript Question

Javascript to remove spaces from .value

//loop thought all the sku field
$('.optionSku').each(function() {

//if found field are empty
if (jQuery.trim(this.value) == "") {

//loop thought all the name field to copy to the empty field
$('.optionName').each(function() {

if ($(this).closest("tr").find(".optionSku").val() == "") {

empty++;
$(this).closest("tr").find(".optionSku").val($(this).val());
}

});
}
})


How to remove space from this.value?
I try to put
if (jQuery.trim(this.value) == "")
, but it cannot remove the space as well.

Answer
this.value =  this.value.trim(); 
//you need to assign the trimmed value back to it.