Hi folks,
I am trying to use jQuery each() to iterate across a group of checkboxes named supplier_type[]. They all have unique ids so I could just re-write this to handle an array of unique ids but I wanted to figure out where I went wrong here.
The alert shows that while intIndex sees the correct number of elements this
always holds the first element.
function setUp(){
$( 'input[name=supplier_type[]]' ).each(
function( intIndex ){
var type = $(this+':checked').val() + 'Table';
$("#"+type).show("slow");
alert($(this+':checked').val()); // sees first one each iter
}
);
}
So how do I address the correct element? Do I need to use bind()?
Thanks!
JG
// Edit Working version based on Drew Wills response. Thanks Drew!
function setUp(){
$( 'input[name=supplier_type[]]' ).each(
function( intIndex ){
if($(this).attr('checked')) {
var type = $(this).val() + 'Table';
$("#"+type).show("slow");
}
}
);
}