Ratchet Button
Ratchet data-attribute button
HTML
<button class="button" data-count="3">button</button>
CSS
body {
margin: 2em;
}
[class*="button"] {
position: relative;
display: inline-block;
padding: 4px 12px;
margin: 0;
font-weight: bold;
line-height: 18px;
color: #333;
text-align: center;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
vertical-align: top;
cursor: pointer;
background-color: #F8F8F8;
background-image: -webkit-linear-gradient(top, #F8F8F8 0, #D4D4D4 100%);
background-image: linear-gradient(to bottom, #F8F8F8 0, #D4D4D4 100%);
border: 1px solid rgba(0, 0, 0, .3);
border-radius: 3px;
box-shadow: inset 0 1px 1px rgba(255, 255, 255, .4), 0 1px 2px rgba(0, 0, 0, .05);
}
[class*="button"] [class*="count"] {
content: attr('data-count');
padding-top: 2px;
padding-bottom: 2px;
margin-right: -4px;
margin-left: 4px;
text-shadow: none;
background-color: rgba(0, 0, 0, .2);
box-shadow: inset 0 1px 1px -1px black, 0 1px 1px -1px white;
}
[class*="count"] {
display: inline-block;
padding: 4px 9px;
font-size: 12px;
font-weight: bold;
line-height: 13px;
color: white;
background-color: rgba(0, 0, 0, .3);
border-radius: 100px;
}
[class*="button"]:before {
content: attr(data-count);
display: inline-block;
float:right;
padding: 2px 9px;
margin-left: 4px;
font-size: 12px;
font-weight: bold;
line-height: 13px;
color: white;
text-shadow: none;
background-color: rgba(0, 0, 0, .2);
border-radius: 100px;
box-shadow: inset 0 1px 1px -1px black, 0 1px 1px -1px white;
}
[class*="button"]:active {
padding-top: 5px;
padding-bottom: 3px;
color: #333;
background-color: #CCC;
background-image: none;
box-shadow: inset 0 3px 3px rgba(0, 0, 0, .2);
}
JavaScript
$('.button').click(function(){
var count = $(this).attr('data-count');
count++;
$(this).attr('data-count', count);
});