If I set my attributes individually, they are both correct afterwards:
document.getElementById("FlightPanels").style.height = (PANEL_HEIGHT + 20) + "px";
document.getElementById("FlightPanels").style.width = container_width + "px";
Even if I set width first, then height, they are both correct.
However, if I use setAttribute():
document.getElementById("FlightPanels").setAttribute("style", "height:" + (PANEL_HEIGHT + 00) + "px");
document.getElementById("FlightPanels").setAttribute("style", "width:" + container_width + "px");
If I set height first, width is lost. If I set width first, height is lost.
I've seen solutions that use setAttribute() to set all the desired attributes in a single call, passing a javascript object with multiple attributes to be set.
This to me seems ridiculously more complex and far less readable than just setting the attributes directly individually.
I find the individual setting approach far more easy to read and comprehend if I have a large number of attributes to be set.
My question is, is there some compelling reason, that maybe I am unaware of, that makes setAttribute() the preferred solution? Should I be using setAttribute() for some principled or "best practices" reason? Or is it OK to just set the attributes individually as shown above?
I want the code to not just work, but also be standards compliant.
EDIT: Thanks for the input, folks, but part of my question has to do with why do two subsequent calls to setAttribute() undo each other. Is it because I am misusing it in some way? Or is this the intended design of the function? In that respect, it is not a duplicate of anything because the marked duplicate question does not address this matter. But your input has been helpful. Thanks.