+1 vote
by
function reTransform(item,addClass){
item.classList.add(`${addClass}`) или еще пробовал item.classList.add(addClass)
}
reTransform(item, 'className' )
It blows on TypeError, how to write a function with this idea.
by
Are you sure that the item inside the function is a DOM element?
by
Yes, the trap of weak typing in JS.
by
alexalexes , thanks for the tip. I spent an hour looking at this piece of code to understand that item is a NodeList.

1 Answer

0 votes
by
Try this
function reTransform(item,addClass){
let class = addClass;
item.classList.add(class)
}
reTransform(item, 'className' )
...