Hello, how can I insert text in an input and when I enter this text, it is displayed in a div, but if I insert another text, the old one is not deleted, only if I delete it myself.
what I want to do exactly is like the label field of this page, but instead of saving it in the input, save it in a div and be able to delete it, I attach an image
With this code I write everything before pressing enter.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Incluye texto con jQuery</title>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function (){
$('#campo').on('keyup', function(){
var valor = $('#campo').val();
$('#reflejar').text(valor);
//$('#campo').val("Hola mundo");
});
});
</script>
</head>
<body>
<input type="text" id="campo">
<div id="reflejar"></div>
</body>
</html>