JSFiddle - React, Tailwind, and code Playground
HTML
<div class="slider-frame">
<span class="slider-button">OFF</span>
</div>
CSS
.slider-frame {
position: relative;
display: block;
margin: 0 auto;
width: 84px;
height: 27px;
background-color: rgb(246, 249, 251);
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: inset 0px 0px 4px 0 rgba(0, 0, 0, 0.25);
-moz-box-shadow: inset 0px 0px 4px 0 rgba(0, 0, 0, 0.25);
box-shadow: inset 0px 0px 4px 0 rgba(0, 0, 0, 0.25);
}
.slider-button {
display: block;
width: 43px;
height: 27px;
line-height: 27px;
background: #EDF2F7;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-transition: all 0.25s ease-in-out;
-moz-transition: all 0.25s ease-in-out;
transition: all 0.25s ease-in-out;
color: #000;
font-family:sans-serif;
font-size:11px;
font-weight:bold;
text-align: center;
cursor: pointer;
-webkit-box-shadow: inset 0px 0px 4px 0 rgba(0, 0, 0, 0.25);
-moz-box-shadow: inset 0px 0px 4px 0 rgba(0, 0, 0, 0.25);
box-shadow: inset 0px 0px 4px 0 rgba(0, 0, 0, 0.25);
}
.slider-button.on {
margin-left: 40px;
background: #EDF2F7;
}
JavaScript
$.fn.toggleClick = function(){
var methods = arguments, // store the passed arguments for future reference
count = methods.length; // cache the number of methods
//use return this to maintain jQuery chainability
return this.each(function(i, item){
// for each element you bind to
var index = 0; // create a local counter for that element
$(item).click(function(){ // bind a click handler to that element
return methods[index++ % count].apply(this,arguments); // that when called will apply the 'index'th method to that element
// the index % count means that we constrain our iterator between 0 and (count-1)
});
});
};
$('.slider-button').toggleClick (function(){
$(this).addClass('on').html('Quizz');
},function(){
$(this).removeClass('on').html('Read');
});
});