Home > Software design >  Change a part of string to a variable, but its already within quotes
Change a part of string to a variable, but its already within quotes

Time:10-14

so i have a command like so:

body.style.backgroundImage = `${"url('./images/3.jpg')"}`

Is there a way i can change the number of the jpg using a variable despite it being encased in a ''? or do i have to replace my structure entirely?

CodePudding user response:

Try this:

var num = 3
body.style.backgroundImage = `url('./images/${num}.jpg')`
  • Related