I try to append text when some id changes.
<div class="col-sm-1">
<input name="stime" type="text" class="form-control" id="stime" placeholder="00:00" required maxlength="5" />
<span class="form-control-feedback"></span>
</div>
When id stime
changes, I want to append a text to the form-control-feedback
class.
This is my script, but nothing changes.
$("#stime").change(function (e) {
var time = $("#stime").val();
$("#stime").find(".form-control-feedback").append("* Check Format Time (HH:mm)");
});
2
Answers
You want to use
.siblings()
instead of.find()
because the.form-control-feedback
element isn’t a child of#stime
, but instead a sibling.You’re also probably looking for
.text()
, not.append()
you can do the following
but since the input is unique by id I’d rather assign the id to the span as well. Then
or
if you don’t want to append but rather replace