Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count empty text fields in jQuery

Tags:

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?

like image 445
t56k Avatar asked Mar 06 '26 22:03

t56k


1 Answers

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">
like image 110
Suresh Atta Avatar answered Mar 08 '26 12:03

Suresh Atta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!