skip to Main Content
root.style.setProperty('--services-box-delay-"+ i +"', totalServicesLines + "s");

This is seemingly so simple, but I can’t get it to work due to (probably) variable escaping wrong understanding.

I have two variables here: i and totalServicesLines.
What is wrong here?

2

Answers


  1. Chosen as BEST ANSWER

    Looks weird, but on base of what Mohammed suggested this one works:

    root.style.setProperty('--services-box-delay-'+ i +'', totalServicesLines + "s");
    

  2. Do like this and I think it will work:

    root.style.setProperty('--services-box-delay-"'+ i +'"', totalServicesLines + "s");
    

    Example:
    If i = 1 and totalServicesLines = 3
    With your code, you will get root.style.setProperty('--services-box-delay-"i"', "3s");
    The variable i will not be evaluated.

    Instead, if you add " before and after i, it will be like this:
    root.style.setProperty('--services-box-delay-1', "3s");.

    And these are js and not css variables.

    The css property that you’re trying to chabge is –services-box-delay-"1" which will get "3s" as value.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search