I've the following group of buttons and when those button or buttons is/are clicked in the group then the color of the clicked buttons must be high-lightened. How do I achieve this using toggle class or else please share me with any another approach if not toggleclass.
<div class="btn-group" data-toggle="buttons-checkbox">
<div class='input-group input-group-sm'>
<span class="input-group-addon">Week</span></div>
<button class="btn" name="WeekButtonGroup" id="week1_sat">
S</button>
<button class="btn" name="WeekButtonGroup" id="week1_sun">
S</button>
<button class="btn" name="WeekButtonGroup" id="week1_mon">
M</button>
<button class="btn" name="WeekButtonGroup" id="week1_tue">
T</button>
<button class="btn" name="WeekButtonGroup" id="week1_wen">
W</button>
<button class="btn" name="WeekButtonGroup" id="week1_thu">
T</button>
<button class="btn" name="WeekButtonGroup" id="week1_fri">
F</button>
</div>
</div>
function highlightwhenclicked() {
$('[name="WeekButtonGroup"]').each(function (index, element) {
$(this).click(function () {
$(this).removeClass('active');
}
})
}
I know $(this).toggleClass can do this but how? I don't mind about what color but button must be high-lightened when clicked. Thanks in advance.
How about something like this?
$('.btn').click(function() {
$(this).toggleClass('clicked');
});
Here's a fiddle: http://jsfiddle.net/Niffler/4uzRj/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.