I'm recently new at programming and JavaScript. I'm not sure why this doesn't work. I'm trying to insert numbers into an empty array. And then have them displayed into the div with the id of "value".
My JavaScript:
var array = new Array();
// var array = [];
$(document).ready(function() {
$('#btn').on('click', function() {
var $input = $('#input').val();
array.push($input);
});
$('#value').text(array);
console.log(array);
});
My HTML:
<div id="number">
<input type="text" id="input">
<button id="btn"> Submit </button>
</div>
$('#value).text(array)inside the click handler.