Categories
JavaScript Answers

How to use CSS selector for targeting only immediate children and not other identical descendants?

Spread the love

Sometimes, we want to use CSS selector for targeting only immediate children and not other identical descendants.

In this article, we’ll look at how to use CSS selector for targeting only immediate children and not other identical descendants.

How to use CSS selector for targeting only immediate children and not other identical descendants?

To use CSS selector for targeting only immediate children and not other identical descendants, we can use the > operator.

For instance, we write

ul > li

to select the li elements that are the immediate children of a ul element.

Conclusion

To use CSS selector for targeting only immediate children and not other identical descendants, we can use the > operator.

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 *