Algorithm
Algorithm

Reputation: 329

How can I find a space character in an <input> using CSS3 selectors?

My way: code

<form>
    <input type="text" value="">
    <input type="submit" value="submit"> type a space and press Submit
</form>

$('form').submit(function(){
    if($('input').val() == ' ') {
        alert($('input').val().length);
    }
   return false;    
});

But I'd like to solve this problem using CSS3 selectors like $('input[value*=" "]')

Upvotes: 0

Views: 320

Answers (2)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196051

If you are asking to use CSS3 selector through jquery then $(':input[value*=" "]') should do it.

example: http://www.jsfiddle.net/gaby/cruRd/

If you want to create an actual CSS3 rule in your stylesheet then input[value*=' ']{..} will work, but only for values in the actual attribute (in the source code) and not the value as modified inside the browser..

example: http://www.jsfiddle.net/gaby/VzE9T/

Upvotes: 2

linkyndy
linkyndy

Reputation: 17910

As far as I know, you cannot manipulate data with CSS; it's a formatting language. You don't have variables or functions which help you find something in a string. Use JS instead.

Upvotes: 2

Related Questions