Categories
JavaScript Answers

How to add a class conditionally to div inline with Jade?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *