This is my html code:
<!DOCTYPE html>
<html>
<head>
<title>Testing Event Listener</title>
</head>
<body>
<h1>Testing Event Listener</h1><br>
<input id="userinput" type="text" placeholder="Enter Elements">
<button id="enter">Enter</button>
<ul>
<li>Javascript</li>
<li>Python</li>
<li>Ruby On Rails</li>
</ul>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
and this is my javascript code :
var input= document.getElementById("userinput");
var button= document.getElementById("enter");
var ul= document.querySelector("ul");
function inputLenght(){
return input.value.lenght;
}
function creatListElement(){
var li=document.createElement("li");
li.appendChild(document.createTextNode(input.value));
ul.appendChild(li);
input.value="";
}
function addListAfterClick(){
if(inputLenght> 0){
creatListElement();
}
}
button.addEventListener("click",addListAfterClick);
This program is not showing any error but it is supposed to add item inside <ul> and a <li> that we write inside placeholder but it is not doing any thing