miszczu miszczu - 3 years ago 270
HTML Question

This with other selector

I'm trying to display number of selected checkbox in each div, but don't know how to select

span
.

This
$("input[@type=checkbox]:checked",this).length
works fine, I've put it in alert and number is correct, but I don't know how to select
#skills div h3 span
for each div.

html

<td id="skills" colspan="2">
<div id="skills_0">
<h3>IT<span></span></h3>
<input type="checkbox" name=".." id=".." val=".." /> <label for="..">..</label>
...<!-- more inputs -->
</div>
...<!-- more divs -->
</td>


jQuery:

$(document).ready( function () {
$('#skills div').each( function () {
$("h3 span",this).html($("input[@type=checkbox]:checked",this).length);
});
});

Answer Source

try this:

/* $(this).find('span').html($("input[@type=checkbox]:checked",this).length); */

The new update code:

$(this).find("h3 span").html($("input[@type=checkbox]:checked",this).length);

demo:

http://jsfiddle.net/ongisnade/VQutV/3/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download