javascript - Limit various checkbox inside different classes independently -
i'm novice js , jquery , i'm facing problem cannot solve knowledge... have site lets users select different types of salads different options, need limit choices of items , don't know how it. checkboxes resides inside class, have many of them , wanted limit ones in particular class.
$(document).ready(function(){ $('#dressing-1 input[type=checkbox]').click(function(){ if($('#dressing-1 input[type=checkbox]:checked').length>=2){ alert($('#dressing-1 input[type=checkbox]:checked').length); $('#dressing-1 input[type=checkbox]:not(:checked)').prop("disabled", true); } else { $('#dressing-1 input[type=checkbox]').prop("disabled", false); } }); });
this code have right , it's working, first item. make code available of items class .contenido-dressign
, i'm using id #dressing-1
corroborates works well. idea make more elegant code instead of using #dressing-1 #dressing-2.. etc... that's why i'm trying apply container .contenido-dressing
.
this site: lunchtime.cl/menu
the this
in function click refer checkbox itsefl, doesnt call of checkbox. :
$(document).ready(function(){ $('.contenido-dressing').find(':checkbox').change(function(){ var parent = $(this).parent() if(parent.find(':checked').length >= 2){ parent.find(':checkbox:not(:checked)').attr('disabled', true); } else { parent.find(':checkbox').attr('disabled', false ); } }); });
don't need each function, bind checkbox who's div .contenigo-dressing
, find parent.
here fiddle : http://jsfiddle.net/syz9z/
Comments
Post a Comment