5

How to select all input tag in without certain attribute and checks each input value not empty in Jquery

Html

<input type="text" maxlength="255" value="" id="UserName" class="form-error"  >
<input type="text" maxlength="255" value="" id="Password" class="form-error">
<input type="text" maxlength="255" value="" id="Group" class="form-error" inputname="test" >
<input type="text" maxlength="255" value="" id="Aka" class="form-error" inputname="money" >

I want to select all inputs from the current page which dont have attribute as 'inputname'.

Something like

In javascript

var inputs = $('input:not(:has(>[inputname]))');

jQuery.each(inputs, function(input) {
      if (input.value == '')  {
   $(input).next().removeClass('displayNone');
       return false;
   }
});
Justin John
  • 9,223
  • 14
  • 70
  • 129
  • possible duplicate of [jQuery get all divs which do not have class attribute](http://stackoverflow.com/questions/1962247/jquery-get-all-divs-which-do-not-have-class-attribute) – Manse Mar 07 '12 at 10:16

3 Answers3

5

I believe you want

var inputs = $('input:not([inputname])');

Live example

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Is it possible to use multiple selector in not $('input:not([inputname] [type="hidden"])'); – Justin John Mar 07 '12 at 10:19
  • 1
    @Jusnit: [`:not` takes only a "simple selector"](http://www.w3.org/TR/css3-selectors/#negation). So you string them together, e.g. `$('input:not([inputname]):not([type="hidden"])')`. – T.J. Crowder Mar 07 '12 at 10:21
1

$('input:not([inputname])') should do the trick?

darryn.ten
  • 6,784
  • 3
  • 47
  • 65
-4

Use this var input = $(":input");

Srikanth Kshatriy
  • 444
  • 1
  • 4
  • 10