How do I pass the element that is being loop to event handler.
foo.hbs
<div>
{{#each products}}
// some html code
<p>{{this}}</p> <!-- output product object -->
<button onclick="foo(this)">Add</button> <!-- output button object-->
<button onclick="foo({{this._id}})">Add</button> <!-- uncaught syntax error -->
{{/each}}
</div>
<script type="text/javascript">
function foo(product) {
console.log(product);
}
</script>
The above code: product
argument gives me the HTMLButton
instead of product
of current iteration.
Question: How do I pass product
instead of button
element to the handler?
I'm using express-handlerbars
.