I want to style element in javascript easily but this function doesn't work
const addStyles = function (el, styles) {
Object.assign(el.style, styles);
}
You need to get the element first, then access the style property (it's a string) and set your CSS there.
Here's an example. As you can see the text is black and there is no CSS, however, with the javascript line I can make it red.
function addStyles(element, style) {
element.style = style;
}
const myElement = document.getElementById("myText");
addStyles(myElement, "color: red; font-size: 25px;");
<p id="myText">Some text<p>