I’ve found this solution on the Internet and applied on my needs
Can someone help me to add the input text to see it on the console.loge?
<body>
<div id="myDIV" class="header">
<h2 style="margin:5px">My Favorite Fruits</h2>
Please Complete your list <input type="text" id="myInput" placeholder="Add...">
<button onclick="newElement()" class="addBtn">Add</button>
</div>
<ul id="fruitlist"></ul>
<script>
var fruits = ["Apple", "Orange", "Banana"];
var list = $("#fruitlist");
$.each(fruits,function(index,value){
$("<li/>").text(value).appendTo(list);
});
// Create a new list item when clicking on the "Add" button
function newElement() {
var li = document.createElement("li");
var inputValue = document.getElementById("myInput").value;
var t = document.createTextNode(inputValue);
li.appendChild(t);
if (inputValue === '') {
alert("You must write something!");
} else {
document.getElementById("fruitlist").appendChild(li);
}
document.getElementById("myInput").value = "";
}
console.log(fruits);
</script>
</body>