-1

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?

Juliver Galleto
  • 8,831
  • 27
  • 86
  • 164
  • 1
    Can you add your _complete_ code, a jsfiddle demo will help solve the problem quickly – Tushar Sep 08 '15 at 05:15
  • possible duplicate of [checking each required input for empty value with jQuery](http://stackoverflow.com/questions/8409429/checking-each-required-input-for-empty-value-with-jquery) – Shehary Sep 08 '15 at 05:21

3 Answers3

3

Try like this:

$("input[required]").filter(function(){
   return $(this).val().length === 0;
}).each(function(){
    alert("s"); 
});
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
0

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="">
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
0

It should be

$("input[required][value='']").each(function)({
    alert("s"); 
});
stef
  • 14,172
  • 2
  • 48
  • 70