title: Unable to get value for list item <ul>
body: <p>It is required that when you click a list item, the function works and displays its value. The list is initially empty, items are added dynamically. Do not use jQuery. Help please.</p>
  <pre><code>&lt;ul id = &quot;subCategoryUL&quot; onclick=&quot;selectSubCategory()&quot;&gt;
  
   &lt;/ul&gt;
  
  switch (a) {
          case 1:{
              var names = [&quot;Value1&quot;, &quot;Value2&quot;, &quot;Value3&quot;];
              for (var i = 0; i &lt; names.length; i++) {
                  var name = names[i];
                  var li = document.createElement('li');
                  li.innerHTML = name;
                  li.style.font.fontsize(150);
                  document.getElementById('subCategoryUL').appendChild(li);
              }
          }
      }
  
  function selectSubCategory(){
          var selectedSubCategory = document.getElementById('subCategoryUL');
          console.log(&quot;subCategoryULR &quot;+selectedSubCategory.innerText);//+subCategory);
          
  }
  </code></pre>