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 :: como calcular porcentaje en javascript 
Javascript :: get month in two digit in javascript date 
Javascript :: how to upload file in material ui 
Javascript :: pagination in strapi 
Javascript :: navigator.clipboard is undefined 
Javascript :: svelte ondestroy 
Javascript :: remove node module 
Javascript :: how to test on user reaction discord.js 
Javascript :: jquery on ready 
Javascript :: settext javascript 
Javascript :: match password and confirm password in javascript if true then submit form 
Javascript :: check if an object contains a value in javascript 
Javascript :: js bundle with popper bootstrap 
Javascript :: nestjs version 
Javascript :: add element to array javascript 
Javascript :: cypress custom error message 
Javascript :: js number with four decimal places 
Javascript :: map function in react 
Javascript :: add bootstrap to angular 13 
Javascript :: javascript detect when number of elements change 
Javascript :: axios send post data 
Javascript :: on click button change route next js 
Javascript :: drupal 8 check if current page is node 
Javascript :: regex email pattern 
Javascript :: convert date to string format dd/mm/yyyy javascript 
Javascript :: javascript function argument type 
Javascript :: json with multiple objects 
Javascript :: permutation javascript 
Javascript :: nested loops js 
Javascript :: bootstrap alert auto close 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =