What is the best way to test for an empty string with jquery-out-of-the-box?

if (!a) {
  // is emtpy
}

To ignore white space for strings:

if (!a.trim()) {
    // is empty or whitespace
}

If you need legacy support (IE8-) for trim(), use $.trim or a polyfill.

Leave a Comment