How to use jQuery's trim() function

Gideon picture Gideon · Dec 3, 2012 · Viewed 49.4k times · Source

As discussed in many questions on stack - IE 8 wont accept .trim(), but the jQuery framework takes care of that.

I don't know how to translate my function to use that version of trim (I thought I was already using jQuery), could someone advise? Here is my code:

$('input').val(function(index, val){
    return val.replace('Please Select', '').trim();
});

This is designed to replace the string with nothing.

I've tried:

$('input').val(function(index, val){
    return val.replace('Please Select', '')$.trim();
});

but that was no good.

Answer

Tetaxa picture Tetaxa · Dec 3, 2012
$.trim(val.replace('Please Select', ''))

http://api.jquery.com/jQuery.trim/