I'm trying to create a function that takes the value of an input field and places it in div. But I'm not getting it to work.
Note: I need to get only numeric values.
Follow my code:
$( "#testar" ).click(function() {
$('#txtDistancia').on('input', function () {
var valor = $(this).val();
$('#valorkm').html(valor);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputname="distancia" type="text" id="txtDistancia" value="7,5 km">
<p></p>
<input type="button" value="Testar" id="testar" class="btn btn-success" />
<p></p>
<div id="valorkm"></div>
UPDATE: I would like the person to test the localhost code, because two people helped me, I saw the code working here and also through Fiddle, but testing on localhost does not work.