[Solved] How can I console.log the second li element using javascript onclick


Just use the querySelectorAll() method instead and target the second li element like this:

document.querySelectorAll("#list li")[1].onclick = () => {
  console.log("Biker Jacket");
};
<h3>Shirts</h3>
<ul id='list'>
    <li>Biker Jacket</li>
    <li>Mens Shirt</li>
</ul>

1

solved How can I console.log the second li element using javascript onclick