jQuery addClass example

Change class name on click in jQuery

by veer_vin

HTML

<div id="chatBotIcon">
  <div class="before"></div>
  <div class="after"></div>
</div>

CSS

#chatBotIcon {
  position: relative;
  border-radius: 50%;
  width: 76px;
  height: 76px;
  border: 2px solid #fff;
  background-image: url("https://author-lundbeck-dev63.adobecqms.net/etc.clientlibs/lundbeck/lulaunch-portal/components/content/chatbot/clientlibs/resources/images/lun_luq_icon.png");
	background-size: 100%;
  background-repeat: no-repeat;
  transition: all 0.5s;
  background-position: 0 0;
  -webkit-transition: all 0.5s;
  -o-transition: all 0.5s;
  -moz-transition: all 0.5s;
  z-index: 2;
  cursor: pointer;
}

#chatBotIcon .before,
#chatBotIcon .after {
    content: '';
    position: absolute;
    width: 32px;
    height: 2px;
    background-color: transparent;
    border-radius: 0;
    top: 21px;
    -webkit-transition: 50ms ease-out;
    -moz-transition: 50ms ease-out;
    -o-transition: 50ms ease-out;
    transition: 50ms ease-out;
    z-index: 0;
}

#chatBotIcon .before {
    left: 7px;
}
#chatBotIcon .after {
    -webkit-transform: rotate(-90deg);
    -moz-transform: rotate(-90deg);
    transform: rotate(-90deg);
    right: 7px;
}

#chatBotIcon.active {
  width: 45px;
  height: 45px;
  animation: gradient 150ms;
  background: #272666;
  border: 1px solid #717171;
  padding-bottom: 1px;
}

#chatBotIcon.active .before {
  background-color: #fff;
    -ms-transform: rotate(225deg);
    -webkit-transform: rotate(225deg);
    -moz-transform: rotate(225deg);
    transform: rotate(225deg);
    -webkit-transition: 600ms ease-in-out all;
    -moz-transition: 600ms ease-in-out all;
    -o-transition: 600ms ease-in-out all;
    transition: 600ms ease-in-out all;

}
#chatBotIcon.active .after {
  background-color: #fff;
    -ms-transform: rotate(-225deg);
    -webkit-transform: rotate(-225deg);
    -moz-transform: rotate(-225deg);
    transform: rotate(-225deg);
    -webkit-transition: 550ms ease-in all;
    -moz-transition: 550ms ease-in all;
    -o-transition: 550ms ease-in all;
    transition: 550ms ease-in all;
}

@keyframes gradient {
  0% {
   ...

JavaScript

$("#chatBotIcon").click(function(){
		$(this).toggleClass("active");
});