Answers for "how to make a <li> when clicked on a button js"

0

how to make a <li> 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
  });
})();
Posted by: Guest on August-16-2021
0

how to make a <li> when clicked on a button js

function AddLi(str)
{
    var li = document.createElement('li');
    li.appendChild(document.createTextNode(str))
    li.innerHTML += ' <button onclick="this.parentNode.remove()">-</button>';
    document.getElementById("out").appendChild(li);
}
Posted by: Guest on August-16-2021
0

how to make a <li> when clicked on a button js

<div>
  <input id="text" type="text" />
  <button id="add">Add</button>
</div>

<ul id="list">
  <li>example item</li>
</ul>
Posted by: Guest on August-16-2021
0

how to make a <li> when clicked on a button js

<form>
    <input type="text" name="userinput">
    <input type="button" value="Add LI" onclick="AddLi(userinput.value)">
</form> 
<span id="out"/>
Posted by: Guest on August-16-2021

Code answers related to "how to make a <li> when clicked on a button js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language