For what you posted to work, the values should be explicitly set to value=""
, and then you can select the elements input
, select
and textarea
you want with the following expression:
$("input[value=''], select:has(option[value='']:selected), textarea:empty")
EDIT
I made an improvement in the expression to also 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")
Unfortunately, it seems that these selectors can only see the original values printed in HTML, not the current values ... with the exception of the selector for
select
.
EDIT 2
You can, however, create your own selector, as described in the SOEN response code: link
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 use this:
- for values beginning with "test":
$('input:field-value(^teste)');
- for values that contain "test":
$('input:field-value(*teste)');
- for values that end with "test":
$('input:field-value($teste)');
- for values that are not equal to "test":
$('input:field-value(!teste)');
- for values that are 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. =)