3

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

For some reason this is not doing it for me. Someone please put me out of my misery :)

$('input.booked:not(:empty)').length
1
  • 2
    From Docs. ":empty" selects all elements that have no children (including text nodes) Commented Jun 3, 2011 at 3:19

2 Answers 2

12

Try this:

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

empty returns nodes with no children, which isn't what you want.

Sign up to request clarification or add additional context in comments.

Comments

5

the :empty selector filters to elements that have no child nodes. What you want is an attribute equals selector...

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.