Using each() for multiple selectors?

Using each() for multiple selectors?

Hi,

The following code should check each input of type text and of type password and add a class to the input and it's label if the input has a value;

But it works only for inputs of type text, but not for inputs of type password!:

  1.       function showAutoFillValue() {
  2.         $('input[type=text], input[type=password]').each(function() {
  3.           var input_value = $(this).val();
  4.           if (input_value != '') {
  5.             $(this).addClass('dirty').prev('label').addClass('dirty');
  6.           }
  7.         });
  8.       }
  9.       setTimeout(showAutoFillValue, 500);

Why is that?

Thanks