i used :empty
selector in .error
class. the problem is that even when there is no content inside the div with class of error, the error class is not removed completely.
when i tested in firebug, i found that the div still has some whitespace and when i remove that extra spaces, the div then disappears.
.error{ border:solid 1px #ff0000; color:#ff0000;}
.error:empty{ display:none;}
the div shows like this on debugging:
<div class="error"> </div>
that extra spaces you see is the problem.
Is there any way i can show
in css to display:none ? pls help.
it is because
<div class="error"> </div>
(demo) is not empty, it has a text node as the child.:empty
Try
Demo: Fiddle
The
:empty
pseudo-class doesn't select elements, containing elements or text (and white space is text).However, there is now the experimental
:blank
pseudo-class which selects elements, containing nothing or just white space, and.error:blank
would select that<div>
element. You should avoid using experimental features in your production code, though.