javascript - Issue on Toggling Two Classes on Bootstrap 3 Radio Button Group -


i trying toggle 2 classes .btn-primary , .btn-default on parent of checked radio on bootsrap 3 radio buttons @ this demo. can see example works @ first check radio , incase of checking radio previous button loses both classes

$(function () {     $('input:radio[name="opts"]').change(function () {         $(this).parent().toggleclass("btn-primary btn-default");     }); }); 

can please let me know why happening , how can fix it? thanks

this should trick -

$(function () {     $('input:radio[name="opts"]').change(function () {         $('.btn').removeclass('btn-default');         $('.btn').addclass('btn-primary');                 $(this).parent().removeclass('btn-primary');         $(this).parent().addclass('btn-default');     }); }); 

here fiddle: http://jsfiddle.net/cmals/1/


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -