Sometimes, we want to add a class conditionally to div inline with Jade.
In this article, we’ll look at how to add a class conditionally to div inline with Jade.
How to add a class conditionally to div inline with Jade?
To add a class conditionally to div inline with Jade, we can use a ternary expression.
For instance, we write
div#demo.collapse(class=typeof fromEdit === "undefined" ? undefined : "in")
to check if fromEdit is undefined with typeof fromEdit === "undefined".
If it is, we set the class attribute to undefined.
Otherwise, we set it to in.
Conclusion
To add a class conditionally to div inline with Jade, we can use a ternary expression.