0

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>
Turnip
  • 35,836
  • 15
  • 89
  • 111
AnotherOne
  • 78
  • 2
  • 11

1 Answers1

0

I found out that the problem is in html file, where i put my button and input inside ul

<ul>
<input type="text"  id="submit" >
<button type="button" id="btn">Add</button>
</ul>
AnotherOne
  • 78
  • 2
  • 11