{{#each posts}}
<input type="hidden" value="{{this.id}}" name="storeInput">
<input type="button" value="Save" name="store">
{{/each}}
how to select specific button with jQyery?
If you have a reference to the post id on the client, you can generate an id or class based on this.id
<input type="hidden" id="post-{{this.id}}" value="{{this.id}}" name="storeInput">
then in js
const buttonEl = $('#post-' + post.id);
You don't need 'post-' but it's nice to namespace things.
I'm positive there's a better way to do this btw
Here, this event listener will filter on the buttons and the look at the previous sibling.
document.addEventListener('click', (e) => { if(e.target.matches('[type="button"]')) { console.log(e.target.previousElementSibling.value); } });
<input type="hidden" value="1" name="storeInput"> <input type="button" value="Save" name="store"> <input type="hidden" value="2" name="storeInput"> <input type="button" value="Save" name="store"> <input type="hidden" value="3" name="storeInput"> <input type="button" value="Save" name="store"> <input type="hidden" value="4" name="storeInput"> <input type="button" value="Save" name="store">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.