In the following code snippet, I want to capture the outermost element(li .menu-item
) when the button is clicked.
Normally, I could use document.querySelector(.menu-item)
, but in this case, these list items are dynamically added so multiple li
elements exist with the menu-item
class.
How do I get the closest li
ancestor in order to extract the values of its children
<li class="menu-item">
<div class="item">
<p>Chicken Veg Roll</p>
<img src="../../assets/img/menu/tasty-rolls.jpg">
</div>
<p class="price">1350.00</p>
<button class="order-btn" form="menu-item-form" type="submit">Add to Order</button>
</li>