I'm just facing a problem while clicking on "Add New Item" button, javascript won't add me a new line (<li>)
in <ul>
I tried making a variable for <ul>
with id="change" which is document.getElementById("change");
On the other hand, I just added an "addEventListener" to this variable, so while I click on this button, a function named "achange" will start working, and add a new line to the <ul>
var icounter = 1;
var c = document.getElementById("change");
c.addEventListener("click", achange);
function achange() {
ulist.innerHTML += "<li> New Item " + icounter + "</li>";
}
<h1 id="header"> List that contains items. </h1>
<button id="change">Add New Item </button>
<ul type="square" id="ulist">
<li> Pizza </li>
<hr align="left" width="20%">
<li> Burger </li>
<hr align="left" width="20%">
<li> Chicken Dinner </li>
<hr align="left" width="20%">
<li> Salad </li>
<hr align="left" width="20%">
</ul>
I'm expecting to add a line which says : "New Item 0" , but nothing happens, any help would be appreciated. Thank you
` **is not a valid child of `
`.** Your HTML is invalid.
– Tyler Roper Jan 17 '19 at 22:46