Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I select empty textareas with CSS?

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.

like image 895
Benjamin Atkin Avatar asked Aug 16 '11 01:08

Benjamin Atkin


People also ask

Can I use CSS empty?

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.


1 Answers

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 */ }
like image 157
LoveAndCoding Avatar answered Oct 01 '22 14:10

LoveAndCoding