I'm trying to loop unto all the input that has a required attribute and which value is empty.
I tried this
$("input[required][value='']").each(function(){
alert("s");
});
but unfortunately, not working. Any help, ideas?
I'm trying to loop unto all the input that has a required attribute and which value is empty.
I tried this
$("input[required][value='']").each(function(){
alert("s");
});
but unfortunately, not working. Any help, ideas?
Try like this:
$("input[required]").filter(function(){
return $(this).val().length === 0;
}).each(function(){
alert("s");
});
Your code should work as it is, just put it inside $(function()...
as shown below.
$(function(){
$("input[required][value='']").each(function(){
alert("s");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<input value="" required>
<input value="">