user2077308
user2077308

Reputation: 451

loop through (input and select) elements and check if the value is empty

I want to loop through all the (input and select) elements inside a div and check if the value is empty and then hide it

I have tried this, but it doesn't work:

$("#tabspanel").find('input[type=text] , select').each(function (){
    if (!(jQuery.trim(this.value).length > 0)) {
        this.hide();
    }
});

Upvotes: 0

Views: 353

Answers (1)

VisioN
VisioN

Reputation: 145378

You should have used $(this).hide(). However, I'd suggest to filter elements first:

$("#tabspanel :input").filter(function() {
    return $.trim(this.value).length === 0;
}).hide();

Upvotes: 3

Related Questions