Originariamente inviato da fcaldera
in altre parole il primo e l'ultimo elemento, ovvero
input[type="checkbox"]:first-child
input[type="checkbox"]:last-child
mmmmm allora... funziona normalmente... cioè se i checkbox sono semplicemente messi nella pagina senza essere dentro a nulla.
Io però ho i vari checkbox tutti ordinati dentro delle celle di una tabella e mi prende sempre ed esclusivamente il primo che trova sia con first-child che last-child.
codice:
var min = $('#check input[type="checkbox"]:first-child').attr('value');
var max = $('#check input[type="checkbox"]:last-child').attr('value');
$('#debug').html("Il valore minimo è: "+ min +" mentre il valore massimo è: "+ max);
<div id="debug"></div>
<div id="check">
<table>
<tr>
<td><input id="chb1" class="chbTest" type="checkbox" value="1"/></td>
<td><input id="chb2" class="chbTest" type="checkbox" value="2"/></td>
<td><input id="chb3" class="chbTest" type="checkbox" value="3"/></td>
<td><input id="chb4" class="chbTest" type="checkbox" value="4"/></td>
<td><input id="chb5" class="chbTest" type="checkbox" value="5"/></td>
</tr>
<tr>
<td><input id="chb1" class="chbTest" type="checkbox" value="6"/></td>
<td><input id="chb2" class="chbTest" type="checkbox" value="7"/></td>
<td><input id="chb3" class="chbTest" type="checkbox" value="8"/></td>
<td><input id="chb4" class="chbTest" type="checkbox" value="9"/></td>
<td><input id="chb5" class="chbTest" type="checkbox" value="10"/></td>
</tr>
</table>
</div>
Continuo ad indagare ma come si risolve in questo caso?
mmmm....