I was using the setAttribute method and noticed that if I use it consecutively, only the first time I use it the DOM elements changes, whereas the second time it doesn't work. And i don't understand why.
example, if i write this:
grid.setAttribute("style", `grid-template-rows:repeat(auto-fill,${width/size}px);`);
grid.setAttribute("style", `grid-template-columns:repeat(auto-fill,${width/size}px);`);
only the grid-template-rows changes.
But if i put it all in one line like this:
grid.setAttribute("style", `grid-template-columns:repeat(auto-fill,${width/size}px); grid-template-rows:repeat(auto-fill,${width/size}px);`);
then both values change, which gives the desired outcome.
Can anyone explain me why the first instance doesn't work?
setAttributeit will always replays old one, it's not append !setAttributeto set styles anyway, instead usegrid.style.gridTemplateColumns = ...-- or better still use classes.