Skip to content
Advertisement

how to style the variable on JS without DOM

I’m about to style the “newResult” with green if passed and red if failed. I’m confused how to style them since the “newResult” is not DOM.

JavaScript

Advertisement

Answer

You can make use of JavaScript template literals, ternary/conditional operator and inline CSS to accomplish what you’re looking for.

The syntax might look confusing at first look, but it does the job.

JavaScript

OutPut

VS code picture

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement