JQuery counts non-empty fields

Trying to count the number of input fields of the '.booked' class that are NOT empty (i.e. they have some kind of value entered.

For some reason this does not do this for me. Someone please spare me from my misery :)

$('input.booked:not(:empty)').length
+3
source share
2 answers

Try the following:

$('input.booked[value!=""]').length

empty returns nodes without children, which is not what you want.

+11
source

:emptyselector filters for elements that do not have child nodes. What you want is an attribute equal to a selector ...

$("input.booked:not([value=''])").length
+5
source

All Articles