views:

423

answers:

3

Hello all,

I am making use of trim() like so:

if($('#group_field').val().trim()!=''){

Where group_field is an input element of type text. This works in Firefox but when I try it on IE8 it gives me this error:

Message: Object doesn't support this property or method

When I remove the trim(), it works fine on IE8. I thought the way I am using trim() is correct?

Thanks all for any help

+3  A: 

Try this instead:

if($.trim($('#group_field').val()) != ''){

More Info:

Sarfraz
Thanks, I thought JQuery's functions were chain-able and that's how they all worked!
Abs
@Abs: You are welcome...
Sarfraz
@Abs: `val()` does not return a jQuery object, so chaining is out of the option. You were calling the `trim()` method on a string, but IE does not know about `String.trim`.
janmoesen
@janmoesen- Ah, I see! Thank you for the explanation.
Abs
+1  A: 

You should use $.trim, like this:

if($.trim($('#group_field').val()) !='') {
    // ...
}
Alexander Gyoshev
+1  A: 

As far as I know, Javascript String don't has method trim. http://www.w3schools.com/jsref/jsref_obj_string.asp
If you want to use function trim, then use

<script>
    $.trim(string);
</script>
Bang Dao