I use jquery autocomplete feature.
$(document).ready(function () {
$("#suggest").autocomplete({
delay: 100,
source: function (request, response) {
// Suggest URL
var suggestURL = "https://suggestqueries.google.com/complete/search?client=chrome&q=%QUERY";
suggestURL = suggestURL.replace('%QUERY', request.term);
// JSONP Request
$.ajax({
method: 'GET',
dataType: 'jsonp',
jsonpCallback: 'jsonCallback',
url: suggestURL
})
.success(function(data){
response(data[1]);
});
},
select: function( event, ui ){$('.tags_id').text(ui.item.value);},
});
});
<link href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<input type="text" placeholder="type something ..." id="suggest" />
Chose: <span class="tags_id"></span>
Here is FIDDLE!
As you can see when I select item from autocomplete it displayed in span element, and when I start to print or if I erase text in autocomplete input the previous selection is displayed, while I need to remove the previous selection each time I print in autocomplete input or I erase it.
My question is how to clear tags_id span when I print in the autocomplete input or I delete all text from it?