How do I loop through a list of li tags inside a ul in order to get the textContent of the clicked li element?
var ul = document.getElementsByClassName('ul')[0];
var items = ul.getElementsByTagName('li');
$("li").on("click", function(){
for (var i =0; i<items.length;i++) {
console.log(items[i]);
}
});
My attempt above logs the textContent of all the li elements within the list whereas I only want the textContent of the clicked element. How could I specify the element clicked?
$("li").on("click", function(){console.log($(this).text());});