0
I am doing a javascript exercise, it is asked to add the name of an input in a character array. This vector is already presented and as I press to add it grows on the screen the names. I made this code but I was not successful. Can you give me some strength? Thank you already.
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="app">
<input type="text" id="btn" name="nome">
<button onClick="adicionar()">adicionar</button>
<ul id="lista">
</ul>
</div>
<script>
function adicionar(){
var text = document.querySelector('#btn')
var conteudo = text.value
nomes.push(conteudo)
}
var lista = document.querySelector('#lista')
var nomes = ["Diego", "Leonardo", "João"]
for(var i=0; i< nomes.length;i++)
{
var item = document.createElement('li')
item.appendChild(document.createTextNode(nomes[i]));
lista.appendChild(item)
}
</script>
</body>
i managed to make it work with your tips. Thank you very much Ricardo and sorry me the bad drafting.
– ash
All right, always tries to elaborate the question with maximum information and tries to explain the better purpose, any only to launch on the site dnv :)
– Ricardo Cenci Fabris