I think I should point out that you can't have more than one element with the same ID, they are by definition unique. The reason is that the getElementById method depends on there being only one item with the ID passed to it in the DOM. If there is more than one item then behaviour is undefined.
If you want to treat your checkboxes as a group, then give them the same class instead. <input type="checkbox" class="chkGenre" rel="genre" value="12" title="Rock" /> On Jan 9, 1:57 pm, swfobject_fan <guru4v...@gmail.com> wrote: > Hi, > > I'm using this piece of code to find a set of selected check boxes > that are selected abd build a comma separated list from their values > ('txt' custom attribute). Is this a jQuery standard method? > > e.g > <input type="checkbox" id="chkGenre" rel="genre" value="12" > txt="Rock" /> <br /> > <input type="checkbox" id="chkGenre rel="genre" value="13" txt="Jazz" / > > > > <script type="text/javascript"> > $(document).ready(function(){ > > $("#tryme").click( function(){ > var oChecked = $("input[rel='genre']:checked"); > var checkedGenres = new Array; > for( var i=0; i<oChecked.length; i++ ) { > checkedGenres[i] = oChecked[i].getAttribute('txt'); > } > > alert( checkedGenres.join(", ") ); > $("#divGenres").text(checkedGenres.join(", ")); > }); > > }); > > </script>