0

taken from http://jsfiddle.net/7huEr/220/

I don't understand the line

return $.trim(this.value) === "";

I'm guessing it's returning all the input fields whose val are empty...but can someone explain how .trim and === work together?

mango
  • 1,183
  • 6
  • 17
  • 33

3 Answers3

1

Basically its returning the boolean true or false. it returns true if the value is completely empty, or contains white space only. it returns false otherwise.

srg2k5
  • 266
  • 1
  • 2
  • 6
1

jQuery.trim trims whitespaces from a string. So when you compare resulting string with "" for exact match (type and value) you check for empty input.

Note that unlike == which can compare "1" and 1, === verifies both value and type match. So it generally preferred to use === when type of result is known.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
1

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

In your Example, It returns True if the Value is null.

Incase if the user entered many spaces without any other characters it will return True

Alaeddine
  • 1,571
  • 2
  • 22
  • 46