How to pass an argument from a function in classList.add ('')?

  • 0
    function reTransform(item,addClass){
    item.classList.add(`${addClass}`) или еще пробовал item.classList.add(addClass)
    }
    reTransform(item, 'className' )


    Swears at TypeError how to write a function with such an idea.
    JavaScript Anonymous, Sep 13, 2019

  • 1 Answers
  • 0
    Try it like this

    function reTransform(item,addClass){
    let class = addClass;
    item.classList.add(class)
    }
    reTransform(item, 'className' )
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!