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

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
$(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.


I Am suresh(suresh kumar )a Web developer,Freelancer,webdesigner,UI developer from bangalore. Got 6+ yrs of IT experience . I specialize in standards-based XHTML, CSS and JavaScript web development. Each site I develop is built to be search engine friendly (SEO), using the latest development principles and techniques.

You may also like...

3 Responses

  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 *