I would like to style the placeholder text of a single input field with multiple styles.
I want to style differently the text that is between the span tags in the label (the optional text). The CSS is not working.
$(".label").each(function() {
el = $(this);
label_value = el.text();
el.hide();
el.next('input').val(label_value).addClass("hide");
});
$("input").focus(function() {
el = $(this);
input_value = el.val();
label_value = el.prev('.label').text();
if (input_value == label_value) {
el.val('').removeClass("hide");
}
})
$("input").blur(function() {
el = $(this);
if (el.val() == '') {
label_value = el.prev('.label').text();
el.val(label_value).addClass("hide");
}
});
input.hide span {
color: red
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label class="label">Brand <span>(optional)</span></label>
<input type="text" autocomplete="off" id="brand" name="brand" value="" />
Any suggestions?