Chico Chico - 6 months ago 7x
Javascript Question

How to use a dynamic id variable in a template.find(input:hidden[id='SOME VARIABLE']) declaration?

I wanna know if it's possible do something like this:

In HTML I have:

<input type="hidden" value="{{productName}}" id="{{productId}}">
<button type="button" class="buyProduct" value="{{productId}}">Buy</button>

In Javascript (Meteor) I wanna do:{
click .buyProduct: function(event, template){
var idGeneratedByBtnClick =;
console.log(idGeneratedByBtnClick); // it shows the correct ID for each button
var element = template.find('input:hidden[id='idGeneratedByBtnClick']');

Can i use a variable like this:
input:hidden[id='My Variable here']



I think it's available to use the variable as string. Could you try?

var idGeneratedByBtnClick =;
var element = template.find('input:hidden[id=' + idGeneratedByBtnClick + ']');