I defined this function which checks if a input field is empty or not
function hasValue() {
if ( !!$.trim( $(this).val() ) )
return true;
}
It just works fine for filtering a jQuery Collection
$('#form').find( '.email' ).filter( hasValue );
But I also want to reuse the hasValue()-function for toggeling a class.
$('.input').change( function () {
var empty = hasValue().apply( $(this) ); //throws an error
// var empty = $(this).hasValue(); //doesn't work either
$('#box').find('.required-tmp').toggleClass('required', empty );
});
Any help is appreciated.