I was putting together an simple example to ask another question when I came across the same problem. Here's a basic example to highlight what's happening:
<script type="text/javascript" src="/scripts/jquery-1.3.1.min.js"></ script> <script type="text/javascript"> $(function() { alert($("input[value='']").attr("id")); }); </script> <div> <input type="text" value="1" id="input-1" /> </div> <div> <input type="text" value="" id="input-2" /> </div> <div> <input type="text" value="3" id="input-3" /> </div> I was looking to select empty input but I now might have to loop over them and check .val instead. Anyone know if this is a bug or am I doing something wrong? Adrian On Feb 3, 10:57 pm, brnwdrng <brianwoodr...@gmail.com> wrote: > I have a set of text box inputs in a div, and want to color the empty > ones red (css) when a user attempts to submit incomplete fields. I've > tried this with and without an explicit iterator, as shown in the two > examples below. > > (a) > $("#<%= this.pnlInputFields.ClientID %> input[class='inputFields'] > [value='']").toggleClass('inputFields_empty'); > > (b) > $("#<%= this.pnlInputFields.ClientID %> input > [class='inputFields']").each(function(i) { $(this).toggleClass > ('inputFields_empty', $.trim($(this).val()).length < 1); }); > > The first one fails with an error message indicating that [value=''] > is an unrecognized expression (Firebug), though [value='helloworld'] > works, correctly toggling the inputFields_empty class on (but not off) > wherever it finds "helloworld" in a text box. I've tried countless > variations on this, and can't seem to get it right for an empty field > (tried :empty too). > > The second one (b) works, at least initially, highlighting the empty > text boxes. Not as elegant as something like (a) might be, but I'll > use it if (a) is infeasible. Note that it only works the first time > my button is pushed; subsequent changes in the textbox fields (like > the user erasing them) fail to remove the inputField_empty class (not > posting back, just have a onclick call that runs this validator > method). > > Any suggestions?