Is there a way that I can select a textarea such that $('#id_of_textarea').val()
in jQuery will be ''
? I tried using :empty
. I saw that CSS provides a way to select empty inputs because the text is in the value
attribute ([value=""]
). Is there an attribute for the text in a textarea?
I'm looking for a selector that will work with CSS, not just jQuery.
The :empty CSS pseudo-class represents any element that has no children. Children can be either element nodes or text (including whitespace). Comments, processing instructions, and CSS content do not affect whether an element is considered empty.
Best solution I can think of is a CSS 3 workaround. Set the field to required (and unset it on submit if need be). Then you can use
textarea:invalid { /* style here... probably want to remove box-shadow and such */ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With