I'm sure this is very simple but I'm stuck.
I have an input, when a value is entered I would like to append this value to a <span>
element. Once the value is deleted from the input, I would like to also remove it from the <span>
element.
The issue i'm having is that the input value is removed, but the html 'Name' remains.
<input type="search" id="searchName" type="text">
<div id="searchFilter">
<p><span id="filterName"></span></p>
</div>
$('#searchName').keyup(function() {
if ($('#searchName').length > 0) {
$("#filterName").text('Name: ' + $('#searchName').val());
} else {
$("#filterName").empty();
}
});
Any help is appreciated.