how to implement below jQuery code into knockout js, Actually I'm trying to call this function on a button click event using knockout js, but it's not working
HTML code:
<div>
<ul class="list-group">
<li>
<button id="buttonid">click</button>
Item 1
</li>
<li>
<button id="buttonid">click</button>
Item 2
</li>
</ul>
</div>
jQuery COde:
$('#buttonid').on("click",".list-group-item",function(e){
console.log($(this).text());
console.log(e.target.id);
});
In this code .list-group-item is the class of ul tag. Here I wanna try to get title text of li items.
please guide me to implement above jQuery function in knockout js!
Best Answer
Template
li
element would also output the button textWith Magento Init Script
With Data Mage Init Attribute
Component
In app/design/frontend/[vendor]/[theme]/Magento_Theme/web/js/item-announcer.js:
With Knockout Component
Template
Component
In app/design/frontend/[vendor]/[theme]/Magento_Theme/web/js/item-announcer.js: