javascript - Switch color of button on click (and revert color of other buttons) -
i have 3 buttons, , want change color of button on being selected. see, able change color on selection, need buttona return original color when buttonb selected (at point buttonb should take on selected color) , on. each button selected takes on selected color, buttons not return original color.
please see fiddle: http://jsfiddle.net/fwqv8/
this script:
jquery(document).ready(function(){ jquery('button.account').click(function() { jquery(this).removeclass("account"); jquery(this).addclass("btn-success"); }); }); ideally there default button (buttona) has selected color when page loads initially.
help appreciated. thank you.
you remove btn-success class on buttons in onclick function, add class newly selected
jquery(document).ready(function(){ jquery('button.account').click(function() { jquery('button.btn-success').removeclass('btn-success'); jquery(this).removeclass("account"); jquery(this).addclass("btn-success"); }); }); or have array selected buttons, , removing btn-success class on newly clicked button
Comments
Post a Comment