-1

I have a variable saved as object_id in javascript. I want to target a data attribute by interpolating the object id in to the data attribute.

For example:

$('[data-object-id="${object_id}"]') However this is not finding the attribute. The are no errors. I've tried interpolating using '+' but found it quite fiddly in this instance.

Ben
  • 35
  • 4
  • 1
    [Duplicate](https://google.com/search?q=site%3Astackoverflow.com+js+template+literal+not+working) of [ES6 / ECMA6 template literals - not working](https://stackoverflow.com/q/37245679/4642212). – Sebastian Simon Mar 18 '21 at 17:49

1 Answers1

0

For interpolation in string you need to use backticks(`) string. Try:

$(`[data-object-id="${object_id}"]`)
Ahsan Naveed
  • 104
  • 7