I have this html -
<ol class="subproduct">
<li>
<input type="checkbox" name="extra2" value="Multidispositivo" />
<p class="checkbox"></p>
<h3>test<span class="price"><span>+2</span>€</span></h3>
<p>test words</p>
</li>
<li>
<input type="checkbox" name="extra2" value="Multidispositivo" />
<p class="checkbox"></p>
<h3>test</h3>
<p>test words</p>
</li>
<li>
<input type="checkbox" name="extra2" value="15 min extra" />
<p class="checkbox"></p>
<h3>test/h3>
<p>test words</p>
</li>
<li>
<input type="checkbox" name="extra2" value="Multidispositivo" />
<p class="checkbox"></p>
<h3>test</h3>
<p>test words</p>
</li>
</ol>
which I need to add a class to the li on 'checking' the checkbox. Currently I use this
$(document).ready(function() {
$('.subproduct input:checkbox').change(function(){
if($(this).is(":checked")) {
$(this).parent().toggleClass("checked");
}
});
});
but I need it so that only ever one checkbox is checked by the user so if they check another box it removes the class of any other
How is this possible?
remove the class of all
<li>
's on chnage event... usingremoveClass()
;...and then if checkedtoggleClass()
of that<li>
try this
Try this http://jsfiddle.net/QHuV9/4/
I hope i am taking your question rite
The simplest solution is something like:
And I would advise to use
<input type="radio">
so that the behavior will be understood by user.See this: Sample
try this DEMO