Heei. I have a question. I want to create if value of input is empty, the label remove class, else (if input has a value)
HTML
<div class="input-field">
<input type="email" id="username" name="email" required>
<label for="username">Email Address</label>
</div>
<div class="input-field">
<input type="password" id="password" name="password" required>
<label for="password">Password</label>
</div>
Jquery
$(document).ready(function(){
if ($(".input-field:first-of-type input").val() == '') {
$(".input-field:first-of-type label").removeClass("active");
}
else {
$(".input-field:first-of-type label").addClass("active");
}
});
CSS
label.active {
color: red;
}
I hope, the label inside <div class="input-field"> first-of-type will be red when it has a class active. But it doesn't work. Any idea please?
My work : https://jsfiddle.net/f7nd0obb/8/