jQuery
trim
not working. I wrote the following command to remove white space. Whats wrong in it?
var str = $('input').val(); str = jquery.trim(str); console.log(str);
Fiddle example.
The TRIM function can get rid of white spaces, but it cannot eliminate non-printing characters. Technically, Excel TRIM is designed to only delete value 32 in the 7-bit ASCII system, which is the space character. To remove spaces and non-printing characters in a string, use TRIM in combination with the CLEAN function.
String result = str. trim(); The trim() method will remove both leading and trailing whitespace from a string and return the result.
jQuery.trim()
capital Q?
or $.trim()
Edit (2021): This answer is 11 years old (2010). There are better solutions posted below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With