JavaScript Agregar elemento en la lista
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
ul li{
list-style: none;
border-style:groove;
border-radius: 40px;
}
ul li:hover{
background-color: red;
}
</style>
</head>
<body>
<div class="container">
<div class="box">
<h3>villes:</h3>
<textarea id="text"></textarea>
<br/>
<button id="submit" onclick="submit()">Submit</button>
</div>
<div class="guestList">
<div id="list"></div>
</div>
</div>
<script>
function submit(){
var guestName=document.getElementById('text');
var listData=guestName.value.split('\n');
var listContainer=document.getElementById('list'),
listElement=document.createElement("ul");
listContainer.appendChild(listElement);
var numberOfListItems=listData.length;
var listItem;
for(var i=0; i<numberOfListItems; ++i){
listItem=document.createElement("li");
listItem.innerHTML=listData[i];
listElement.appendChild(listItem);
}
}
</script>
</body>
</html>
rd