Reputation: 575
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>
Upvotes: 0
Views: 70
Reputation: 13
try this, using double quotes
$("#divAdd .test input:text,#divAdd .child input:text").each(function () {
or
$.merge($("selector"), $("selector"));
Upvotes: 0
Reputation: 38112
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.
Upvotes: 2
Reputation: 17366
You can also use add()
$('#divAdd .test input:text').add('#divAdd .child input:text')
Side Note: Textbox id's must be unique!
Upvotes: 0
Reputation: 59292
You don't need ','
. You just need a ,
$('#divAdd .test input:text,#divAdd .child input:text')
Just use ,
to separate the selectors.
Upvotes: 0
Reputation: 152304
Just try with:
$('#divAdd .test input:text, #divAdd .child input:text')
Or for better performance:
$('#divAdd').find('.test, .child').find('input:text')
Upvotes: 2