How to add class on a textbox if its empty? I am using getmdl.io framework. What I want to do is when the textbox is empty I want to add a class which is (is-focused, is-invalid and is-dirty)
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label" id="fn">
<input class="mdl-textfield__input" type="text" id="fullname" name="fullname" autocomplete="off">
<label class="mdl-textfield__label" for="fullname">Full name</label>
</div>
and this is my javascript code when the submit button is click.
function validate () {
var f = _('fullname').value;
if (f == "") {
_('fn').className += " is-invalid";
}
}