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 :: how to pass a component as a prop in react 
Javascript :: how to find keycode in javascript 
Javascript :: twhat is a js promise 
Javascript :: get two types of date formate datepicker 
Javascript :: javascript generate random string from array 
Javascript :: js retry function if error 
Javascript :: disable eslint curly option 
Javascript :: How to make PWAs installable js 
Javascript :: how to remove letters from an array javascript 
Javascript :: onclick timer javascript 
Javascript :: declare array in javascript 
Javascript :: html to jsx 
Javascript :: find saturday with moment js 
Javascript :: react fetch request with content type x-www-form-urlencoded 
Javascript :: passport google authentication node js 
Javascript :: vue js qr code scanner 
Javascript :: express ubuntu ERR_CONNECTION_REFUSED 
Javascript :: call vue function at element load 
Javascript :: this keyword in javascript 
Javascript :: jquery select element inside element 
Javascript :: Fetching data error and pending load check 
Javascript :: react hook useeffect 
Javascript :: javascript export multiple function 
Javascript :: javascript string insensitive compare 
Javascript :: wait 0.5 after function javascript 
Javascript :: angular firebase 
Javascript :: mongoose read 
Javascript :: next auth 
Javascript :: using connect flash 
Javascript :: react native image zoom viewer 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =