After opening one of my web projects in IntelliJ, I noticed some JavaScript hints/errors that Netbeans did not detect.
The error message was:
> Assigned expression type string is not assignable to type CSSStyleDeclaration
This error was related to this line of code:
password.style = "border: 2px solid red";
To resolve this, I directly specified the style like this:
password.style.border = "2px solid red";
Another option suggested by a commenter was:
password.setAttribute("style", "border: 2px solid red";);
My question is about the differences between these approaches. Are there any consequences or risks associated with using the first method? Is there a recommended best practice?
As far as I have tested, the first method works on all browsers I have tried. It's also worth noting the lack of detection by Netbeans for this issue.