How to select all fields in a form with a specific class

I am trying to select all the fields on a form with a specific call name and then select all the others.

my form:

 <form style="margin:20px 0" id="myform_2">
                <p>  Query Name :
                    <input id="full_text_search" name="name" type="text" class="serialize_1">
                </p>
                <p>  Platform : 
                    <select  multiple="multiple" style="width:370px" id="platform" name="platform" class="serialize_1">
                        <option value="android" selected="selected">Android</option>
                        <option value="ios">IOS</option>
                    </select>
                </p>


                <p>  Full Text Search :
                    <input id="full_text_search" name="full_text_search" type="text">
                </p>
                <p>  Package Name :
                    <input id="package_name" name="package_name" type="text">
                </p>
</form>

      

I want the first selector to select inputs with class: "serialize_1". so i try this:

$('#myform_2 :input[class==serialize_1"]');

      

and a second selector to catch everything else, so I try this:

$('#myform_2 :input[class!=serialize_1"]');

      

what am i missing?

thank

+3


source to share


3 answers


To get with a class:

$('#myform_2 :input.serialize_1');

      



To get without a class:

$('#myform_2 :input:not(.serialize_1)');

      

+6


source


to get the class use selector. '

$('#myform_2 :input.serialize_1');

- select inputs with class: "serialize_1"



$('#myform_2 :input:not(.serialize_1)');

- selector to catch everything else

+1


source


Just use the class selector to select elements serialize_1

and the not()

selector to select those that are not:

  $('#myform_2 :input').not('.serialize_1').addClass('blue');
  $('#myform_2 :input.serialize_1').addClass('red');

      

Here comes the WORKING TEST

+1


source







All Articles