Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript add item in list

<!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('
');

        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>
Comment

javascript append list to list

a.push(...b);

var a = [1,2,3];
var b = [4,5,6];
a.push(...b); // [1,2,3,4,5,6]

// The .push method can take multiple arguments.
// You can use the spread operator (...) to pass all
// the elements of the second array as arguments to .push
Comment

PREVIOUS NEXT
Code Example
Javascript :: array check in javascript 
Javascript :: linear equations calculator 
Javascript :: how to insert a value into an array javascript 
Javascript :: two sum js 
Javascript :: add parameter at the end of url from jquery with refreshing 
Javascript :: import an image react in the public folder 
Javascript :: overflowx 
Javascript :: how to sort array least to greatest javascript stACK 
Javascript :: how to create an element in js using the map method 
Javascript :: find unique objects in an array of objects in javascript 5 
Javascript :: how to convert decimal to roman in javascript 
Javascript :: Create JavaScript Strings 
Javascript :: line break in js 
Javascript :: jquery add 
Javascript :: javascript Arrow Function with One Argumen 
Javascript :: jquery datatable update row cell value 
Javascript :: every() method 
Javascript :: javascript remove json element 
Javascript :: mean stack 
Javascript :: react scrip for deplot heroku 
Javascript :: how to cause a whole page reload react redux 
Javascript :: center canvas p5js 
Javascript :: react-load-animations 
Javascript :: parsedate javascript 
Javascript :: js byte size 
Javascript :: Expected an identifier and instead saw ' 
Javascript :: js ,flat 
Javascript :: how to clone an object in javascript 
Javascript :: how to use hidden value in javascript using getelementbyid 
Javascript :: javascript hoisting 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =