t56k
t56k

Reputation: 6981

Count empty text fields in jQuery

I've got this response in my Chrome console for a view:

$('.checklist-17012').length
5

There are five in the view, so that's correct. The problem is that they're all empty, and no matter what I do I can't count the empty ones:

$('.checklist-17012[val=""]').length
0

$('.pdf-checklist-17012[val=null]').length
0

Here's the HTML:

<input type="text" name="30954" id="30954" value="" class="checklist-17012 form-control">

What am I doing wrong?

Upvotes: 3

Views: 40

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 121998

There is no attribute called val. Should be value

$('.checklist-17012[value=""]').length

console.log($('.checklist-17012[value=""]').length)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="30954" id="30954" value="" class="checklist-17012 form-control">

Upvotes: 4

Related Questions