The code below is part of a function that uses a search term in a text field to extract images from the Flickr site. After entering the word to search, it inserts the text below the field, just to show that it is looking for it, but the problem is that whenever I type a new term, it inserts the new term in the page, instead of zeroing the words. images and the term.
var $tag,
$status,
$msg;
if ($("main .container .busca input").val() !== "") {
$status = $("<p>").text($("main .container .busca input").val());
$tag = $("main .container .busca input").val();
$msg = ("<p> Encontramos essas imagens para você:</p>");
$("main .container .busca").append($msg).append($status);
$("main .container .busca input").val("");
};
I would like every time I type a new term, it deletes the previous one, as well as the images, and inserts the new term under the text box. Could someone give me a clue how to do this?