If you need in javascript you could add attribute for the post-id on your loop-item ,f.e. data-post-id (key) and vor the attribute-value {post_id} . Then you can read your attribute (data-post-id) with javascript.
It’s not a bad idea… I found about the attribute “data-interaction-loop-id” which is added natively in the button which triggers the popup insided the looped item. It’s working and I can’t see any disadvantages going this way so far.
jQuery(".loop-button").each(function() {
jQuery(this).click(function() {
var data = jQuery(this).attr("data-interaction-loop-id");
var term = data.slice(-2);
console.log(term);
});
});
I just had a look and it seems that data-interaction-loop-id is added, when there is an interaction applied to the loop item. In a loop without an interaction there’s no such attribute. But in this case you can do it. Glad it works!