Advertisement
elena1234

DOM - how to check for empty innerHTML

Oct 8th, 2021
1,080
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let button = document.querySelector("button");
  3.     let listItems = document.querySelectorAll("li");
  4.     let input = document.querySelector("input");
  5.  
  6.     button.addEventListener('click', functionOrderNameInDB);
  7.     function functionOrderNameInDB() {
  8.         let inputValue = document.getElementsByTagName("input")[0].value;
  9.         let number = Number(inputValue.toUpperCase().charCodeAt(0) - 65);
  10.         if (listItems[number].innerHTML === '') {
  11.             listItems[number].innerHTML += inputValue.charAt(0).toUpperCase() + inputValue.slice(1).toLowerCase();
  12.         } else {
  13.             listItems[number].innerHTML += ", " + inputValue.charAt(0).toUpperCase() + inputValue.slice(1).toLowerCase();
  14.         }
  15.         input.value ='';
  16.     }
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement