Markup-wise, the :empty
selector should allow you to select textareas that have absolutely no content, not even so much as whitespace or a line break. Conversely :not(:empty)
should let you select non-empty textareas.
Selectors in CSS are mostly static though, meaning they don't account for dynamic changes such as if you edit a textarea's content after page load. Furthermore, a selector like :empty
doesn't really account for a textarea's value so much as it checks for the presence (or absence) of content nodes in general, so I suspect it doesn't play well with forms.
If you need to apply styles dynamically based on the value of a form field, you'll need to use a script to check its value using .val()
or something similar every time it updates.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…