How to remove white spaces from the string seems to be a big question. Whether we have global javascript in-built functions that we can use or do we need to write our own custom methods.

Then I thought of going through Jquery way of using trim() method but then finally end up issues in IE7 ( Internet explorer).

var stringValue= ” suresh web developer bangalore”;

You see white spaces in a variable to get rid of it I tried using
Jquery
$(stringValue).trim(); /*issues with IE7*/

So then finally thought of using regular expression

$(stringValue).replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, ”);

Worked like a charm.

Hope this will help.

3 Responses to fix for how to remove remove white spaces using javascript/jquery | issues with trim()

  1. Pat says:

    Hi and thanks for taking the time to describe the terminlogy to the newcomers!

  2. source says:

    Mate! This website is cool. How do you make it look like this !?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get all fix get all the fixes for CSS, Jquery and any web2.0 related queries
Set your Twitter account name in your settings to use the TwitterBar Section.