Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE8 and JQuery's trim()

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

like image 676
Abs Avatar asked Aug 09 '10 10:08

Abs


People also ask

Why trim is used in jQuery?

trim() function removes all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of the supplied string. If these whitespace characters occur in the middle of the string, they are preserved.

Is trim deprecated?

trim() is deprecated.

What is trim Ajax?

The trim() method removes whitespace from both sides of a string. The trim() method does not change the original string.


2 Answers

Try this instead:

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

More Info:

  • http://api.jquery.com/jQuery.trim/
like image 69
Sarfraz Avatar answered Sep 29 '22 07:09

Sarfraz


You should use $.trim, like this:

if($.trim($('#group_field').val()) !='') {     // ... } 
like image 30
Alex Gyoshev Avatar answered Sep 29 '22 07:09

Alex Gyoshev