Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add item to list javascript

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi"); // Fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
Comment

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

PREVIOUS NEXT
Code Example
Javascript :: postman environment variables 
Javascript :: js event target 
Javascript :: remove an element from array javascript 
Javascript :: superagent set cookie 
Javascript :: how to target checkbox in jquery 
Javascript :: javascript object type 
Javascript :: overflowx javascript 
Javascript :: react-infinite-scroller 
Javascript :: how to use the map method in javascript 
Javascript :: js add element to array 
Javascript :: loop an array javascript 
Javascript :: js format date 
Javascript :: math.floor 
Javascript :: how to add id in jquery 
Javascript :: multi dimensional array javascript 
Javascript :: load.json 
Javascript :: how to create two dimensional array in js 
Javascript :: react emoji picker 
Javascript :: mean stack tutorial 
Javascript :: change inptu val 
Javascript :: jquery slider move event 
Javascript :: javascript update multiple values of an object 
Javascript :: javascript loops 
Javascript :: javascript focus on contenteditable not working 
Javascript :: divide an array based on length js 
Javascript :: react change background image on hover 
Javascript :: Slice and Splice -Javascript 
Javascript :: javascript clone object 
Javascript :: Find the longest string from a given array 
Javascript :: where to find node js logs windows logging node.js howto 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =