I have a trouble here when I press the SAVE INPUT button. I want that when I enter the text inside the box, and then click to SAVE INPUT, the output will be the value that I entered (I initialized an array and it worked), but when I do not put anything in the textbox, and click SAVE INPUT, it will return <li> element symbol. How can I make the code break when I do not enter anything? Here is my code:
const inputBtn = document.getElementById("input-btn")
const inputEl = document.getElementById("input-el")
const ulEl = document.getElementById("ul-el")
let myLead = []
inputBtn.addEventListener("click", function() {
myLead.push(inputEl.value)
renderLoad()
inputEl.value = ""
});
function renderLoad() {
let listItems = "";
for (let i = 0; i < myLead.length ; i++ ) {
/* listItems += "<li><a href='#'' target='_blank'>" + myLead[i] + "</li>"; */
listItems += `
<li>
<a href='#' target='_blank'>${myLead[i]}
</li>`;
ulEl.innerHTML = listItems // follow html rule
}
}
e.g. case 1: input with value (My code worked!)
input: "www.google.com"
output:www.google.com
case2: input with no value
input:
output:
(My code does not work with this case! Output shows me "" symbol each time I click SAVE INPUT)