javascript - How can I emulate radio button functionality in jQuery? -
i have 3 buttons, each checkbox:
<div id="btn_group"> <button class="btn"><i class="icon-check-empty"></i> one</button> <button class="btn"><i class="icon-check-empty"></i> two</button> <button class="btn"><i class="icon-check-empty"></i> three</button> </div>
my current jquery looks this:
$('.btn').on('click',function() { $('#btn_group > .btn > i').removeclass('icon-check').addclass('icon-check-empty'); $(this).children('i').toggleclass('icon-check-empty icon-check'); });
here's needs happen:
1) click button 1: button 1 checked, others not checked
2) click button 1 again: button 1 unchecked, others still unchecked
3) click button 1: (see #1)
4) click button 2: button 2 checked, others not checked (like radio button)
basically need set of radio buttons allow uncheck current selection never allow more 1 selected. emulated through js & jquery. can help?
you can single class.
$('.btn').on('click',function() { $(this).toggleclass('icon-check').siblings().removeclass('icon-check'); }
Comments
Post a Comment