0

can i select Elements of different classes at a time?

suppose if i have

      <div id="divAdd">
        <p style="font-size:16px; color:Blue; "></p>
        <p class="test">

            <input:textbox id="id1" type:"text" />

         </p>

        <p class="test">

            <input id="txtMobile" type="text" style="width:120px;" name="txtMobile">
        </p>

        <p class="test">
            <input id="txtMobile" type="text" style="width:120px;"      name="txtMobile">
        </p>

       <p class="child">

       <input id="txtMobile" type="text" style="width:120px;" name="txtMobile">

     </p>

can i select all textboxes in two different classes in this way??

 $('#divAdd .test input:text','#divAdd .child input:text').each(function () {

    count++;

      });
  </div>

5 Answers 5

2

Just try with:

$('#divAdd .test input:text, #divAdd .child input:text')

Or for better performance:

$('#divAdd').find('.test, .child').find('input:text')
2

You don't need the quotes here, you can use comma , to separate multiple selectors:

$('#divAdd .test input:text, #divAdd .child input:text').each(function () {

Also note that:

<input:textbox id="id1" type:"text" />

is not a valid HTML markup, you need to remove :textbox here.

0

You don't need ','. You just need a ,

$('#divAdd .test input:text,#divAdd .child input:text')

Just use , to separate the selectors.

0

You can also use add()

$('#divAdd .test input:text').add('#divAdd .child input:text')

Side Note: Textbox id's must be unique!

0

try this, using double quotes

$("#divAdd .test input:text,#divAdd .child input:text").each(function () {

or

$.merge($("selector"), $("selector"));

Not the answer you're looking for? Browse other questions tagged or ask your own question.