 <p>Try this code</p> <pre><code>$('input').each(function(){ self = $(this) if(!self.val()){ require(self); } }); function require(that){ console.log('Please fill in ' +that.data('validate-msg') + '.'); } </code></pre>