The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Target empty elements using the :empty pseudo-class

Target empty elements using the :empty pseudo-class

0:58
You can target an element that has no child elements by using the `:empty` pseudo-class. With browser support down to IE9, it's solid, easy way to select empty elements without any additional markup. Be aware that whitespace is considered a "child", so `:empty` will not work if the element has no children, but has space between the opening and closing tags.
Watch this lesson now
Avatar
egghead.io

You can target an element that has no child elements by using the :empty pseudo-class. With browser support down to IE9, it's solid, easy way to select empty elements without any additional markup.

Be aware that whitespace is considered a "child", so :empty will not work if the element has no children, but has space between the opening and closing tags.

Avatar
Codilime

Not applying css to :empty elements is not equal to setting 'display: none' to :empty elements.

In reply to egghead.io
Avatar
Nut

Usually egghead courses have great sound. But this and also Prof. Frisby's are absolutely awful. What is wrong with that?

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?