Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to make a
  • when clicked on a button js
  • (function () {
      document.querySelector('#add').addEventListener('click', function () {
        let input = document.querySelector('#text');
        let list = document.querySelector('#list'); 
        
        let item = document.createElement('li'); // create li node
        let itemText = document.createTextNode(input.value); // create text node
        
        item.appendChild(itemText); // append text node to li node
        list.appendChild(item); // append li node to list
        
        input.value = ""; // clear input
      });
    })();
    Source by stackoverflow.com #
     
    PREVIOUS NEXT
    Tagged: #clicked #button #js
    ADD COMMENT
    Topic
    Name
    9+4 =