JavaScript all elements which id starts with an interpolated string

I have some buttons with the same class .btn-plus-minus and an id that starts with “btn-plus-SomeMoreText_1_[…]”.

To select all buttons, I used var buttons = $(".btn-plus-minus[id^='btn-plus-']");

But now I don’t want all buttons, but only these that also match a number. My match[1] returns “SomemoreText_1_” and I want only the buttons with ids starting with btn-plus-SomeMoreText_1_ so I tried:

var plusButtons = $(".btn-plus-minus[id^=`btn-plus-${match[1]}`]");

Unfortunately, the string interpolation inside the id^=... doesn’t seem to work since I get the following exception:

Uncaught Error: Syntax error, unrecognized expression: .btn-plus-minus[id^=btn-plus-${match[1]}]

Is there another way to achieve what I want?

Thanks in advance

Answer

You can’t put a template string in a regular string. Try making the whole string a template string:

var plusButtons = $(`.btn-plus-minus[id^='btn-plus-${match[1]}']`);