I’m trying to use innerHTML to add an li
item according to user input (in a textbox). Is there any way to create new list item other than using createElement
or appendChild
?
const user = document.getElementById('btn');
const inputEle = document.getElementById("submit");
const userList = document.getElementById('itemList');
user.addEventListener('click', (e) => {
userList.innerHTML += `<li>${inputEle.value}</li>`;
});
<input type="text" id="submit">
<button type="button" id="btn">Add</button>
<ul id="itemList"></ul>