Reputation: 451
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
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