Jerko Viskov
Jerko Viskov

Reputation: 3

Insert variable as parameter

I have Javascript code :

document.getElementById("Grid").style.gridTemplateRows = "repeat(3, 2fr)";

How do I insert variable as argument to modify my CSS style, when I try:

"repeat(${MyVariable}, 2fr)"; 

it seems doesn't work ?

Upvotes: 0

Views: 60

Answers (1)

mplungjan
mplungjan

Reputation: 178413

${MyVariable} belongs in backticks (template literals)

so EITHER

document.getElementById("Grid").style.gridTemplateRows = "repeat("+MyVariable+", 2fr)";

OR

document.getElementById("Grid").style.gridTemplateRows = `repeat(${MyVariable}, 2fr)`;

Upvotes: 1

Related Questions