Is there a way to detect whether or not an input has text in it via CSS? I've tried using the :empty
pseudo-class, and I've tried using [value=""]
, neither of which worked. I can't seem to find a single solution to this.
I imagine this must be possible, considering we have pseudo-classes for :checked
, and :indeterminate
, both of which are kind of similar thing.
Please note: I'm doing this for a "Stylish" style, which can't utilize JavaScript.
Also note, that Stylish is used, client-side, on pages that the user does not control.
Yes! you can do it with simple basic attribute with value selector.
Using JS and CSS :not pseudoclass
You can use the
:placeholder-shown
pseudo class. Technically a placeholder is required, but you can use a space instead.This is not possible with css. To implement this you will have to use JavaScript (e.g.
$("#input").val() == ""
).do it on the HTML part like this:
The required parameter will require it to have text in the input field in order to be valid.
and
will work :-)
edit: http://jsfiddle.net/XwZR2/