For what you posted to work, the values must be explicitly defined as value=""
, and then it will be possible to select the elements input
, select
and textarea
you want with the following expression:
$("input[value=''], select:has(option[value='']:selected), textarea:empty")
EDIT
I also improved the expression to select those that do not have the value attribute:
$("input[value=''], input:not([value]), select:has(option[value='']:selected), select:has(option:not([value]):selected), textarea:empty")
Poxa, unfortunately, it seems that these selectors can only see the original values printed in HTML, and not the current values... with the exception of the selector for the select
.
EDIT 2
You can, however, create your own selector, as described in the code of this SOEN response: https://stackoverflow.com/a/15031698/195417
jQuery.extend(
jQuery.expr[':'],
{
/// check that a field's value property has a particular value
'field-value': function (el, indx, args) {
var a, v = $(el).val();
if ( (a = args[3]) ) {
switch ( a.charAt(0) ) {
/// begins with
case '^':
return v.substring(0,a.length-1) == a.substring(1,a.length);
break;
/// ends with
case '$':
return v.substr(v.length-a.length-1,v.length) ==
a.substring(1,a.length);
break;
/// contains
case '*': return v.indexOf(a.substring(1,a.length)) != -1; break;
/// equals
case '=': return v == a.substring(1,a.length); break;
/// not equals
case '!': return v != a.substring(1,a.length); break;
/// equals
default: return v == a; break;
}
}
else {
return !!v;
}
}
}
);
And then wear it like this:
- for values starting with "test":
$('input:field-value(^teste)');
- for values containing "test":
$('input:field-value(*teste)');
- for values ending with "test":
$('input:field-value($teste)');
- for values that are not equal to "test":
$('input:field-value(!teste)');
- for values equal to "test":
$('input:field-value(=teste)');
Do not forget to give an upvote there to the SOEN guy if you find this a good solution... the merit is not mine. =)
$('input:text[value=""]');
– Guerra