Ch Hong Ch Hong - 1 year ago 86
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() == "") {



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 Source
this.value =  this.value.trim(); 
//you need to assign the trimmed value back to it.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download