Reputation: 57
for example I have the following:
<div class="both">
<textarea data-id="1" name="t1">Value 1</textarea>
<input type="checkbox" value="checkbox1" checked="checked" name="c1">
<input type="checkbox" value="checkbox1-2" name="c1">
<input type="checkbox" value="checkbox1-3" name="c1">
</div>
<div class="both">
<textarea data-id="2" name="t2">Value 2</textarea>
<input type="checkbox" value="checkbox2-1" name="c2">
<input type="checkbox" value="checkbox2" checked="checked" name="c2">
<input type="checkbox" value="checkbox2-3" name="c2">
</div>
<div class="both">
<textarea data-id="3" name="t3">Value 3</textarea>
<input type="checkbox" value="checkbox3-1" name="c3">
<input type="checkbox" value="checkbox3-2" name="c3">
<input type="checkbox" value="checkbox3-3" checked="checked" name="c3">
</div>
I want to find out the number of checkboxes in first div element of both.
Stupid question, but I am new in this..
Thanks
Upvotes: 1
Views: 101
Reputation: 13471
$('div.both:first input[type="checkbox"]').length
As the jQuery Doc says here http://api.jquery.com/checkbox-selector/
input[type="checkbox"]
is better than :checkbox
Because :checkbox is a jQuery extension and not part of the CSS specification, queries using :checkbox cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. For better performance in modern browsers, use [type="checkbox"] instead.
Upvotes: 2
Reputation: 26730
$('div.both:first input:checkbox').length
More information: http://api.jquery.com/category/selectors/
Upvotes: 4