How to change the color of a button when pressed using bootstrap?

Can someone show me how to change the button color in bootstrap? I have a group of buttons, and only the pressed button should change color. Thank.

+4
source share
1 answer

Without publishing any code, the best thing I can do for you right now is if you get a simple jQuery function to change the color of a button by switching classes.

Js

// .btn is the class of the element you want to change color
$(".btn").click(function() {
  // Instead of directly editing CSS, toggle a class
  $(this).toggleClass("clicked");
});

CSS

.btn {
  background-color: red;
}

.clicked {
  background-color: blue;
}

EDIT. ashin999, bootstrap ( , , ), . , clicked.

+4

Source: https://habr.com/ru/post/1541701/


All Articles