Search code examples
javascriptjqueryhtmlhtml-input

Shorter way to check that value of multiple input is empty for jquery


let a = $('#plustitle').val().trim();  // input type text
let b = $('#plustags').val().trim(); // input type text
let c = $('#plustory').val().trim(); // textarea

I need to check if any of the above variable is empty, i.e. have value "";

Using jquery each loop - there is a lot of code.

Is there a way to do it in a shorter way.


Solution

  • If we use the fact that an empty string will be falsy we could achieve your requirement with

    if (!(a && b && c)) {
      // one of them is empty
    }