How could I create a selector to use with .is() function in jQuery that represents the following expressions:
$('[name="Person[firstName]"]').val() === ''; // true
$('[name="Person[lastName]"]').val() === ''; // false
With this HTML context
<input name="Person[firstName]" value="" >
<foo bar="true" />
</input>
<input name="Person[lastName]" value="ABCDEFGH" />
:empty Selector Select all elements that have no children (including text nodes).
$('[name="Person[firstName]"]').is(':empty'); // false
$('[name="Person[lastName]"]').is(':empty'); // true
Another try
$('[name="Person[firstName]"]').is('[value=""]'); // true
$('[name="Person[lastName]"]').is('[value=""]'); // true
Note: This is a question for knowledge purposes - and .is() must be used in this solution.
@edit http://jsfiddle.net/2CzWu/2/
It must return false on both expressions
.is()must be used in this solution. Why? Usingis()seems counter-productive to the results you want to achieve.$('[name="Person[lastName]"]').is('[value=""]')returnstruedoes not seem to be the case. The code in that block seems to work as expected for me. jsfiddle.net/2CzWu/1.is()method.