JSFiddle - React, Tailwind, and code Playground
by Abid Shaik
HTML
<div class="counter-widget">
<div class="inner">
<!-- optionally add readonly attribute to input to prevent focus/typing -->
<input id="clickCount" type="text" value="0" />
<label>Clicks</label>
</div>
<ul class="delist button-set">
<li> <a href="#" class="plus-minus-btn">+</a>
</li>
<li> <a href="#" class="plus-minus-btn">-</a>
</li>
</ul>
</div>
<div class="counter-notes">
<textarea id="notes" placeholder="Notes" > </textarea>
</div>
CSS
.delist {
list-style: none;
}
.delist, .delist li {
margin: 0;
padding: 0;
}
.counter-widget {
border: 1px solid #333;
max-width: 200px;
margin: 40px auto;
}
.counter-widget .inner {
padding: 1em 1em 0.5em;
min-height: 100px;
}
.counter-widget input {
border: none;
color: #666;
font-size: 48px;
padding: 0;
max-width: 100%;
box-sizing: border-box;
text-align: center;
}
.counter-notes
{
max-width: 500px;
margin: 40px auto;
}
.counter-notes #notes
{
font-size: 18px;
color: #666;
width: 500px;
height: 95px;
}
}
.counter-widget input:focus {
outline: none;
color: #222;
}
.counter-widget label {
font-size: 16px;
text-align: center;
color: #666;
display: block;
margin: 0px;
padding: 0;
}
.counter-widget label span {
display: block;
color: #666;
}
.button-set {
overflow: hidden;
border-top: 1px solid #333;
}
.button-set li {
width: 50%;
float: left;
box-sizing: border-box;
background: #f3f2f2;
border-right: 1px solid #333;
}
.button-set li:last-of-type {
border-right: none;
}
.button-set a {
display: block;
padding: 0.25em 1em;
font-size: 30px;
text-align: center;
text-decoration: none;
color: #444;
}
.button-set a:hover {
background: #fff;
color: #333;
}
.counter-widget--horizontal {
max-width: 205px;
margin-bottom: 0;
}
.counter-widget--horizontal .button-set {
border-top: 0;
border-left: 1px solid #333;
width: 66.66%;
box-sizing: border-box;
}
.counter-widget--horizontal .button-set a {
font-size: 20px;
}
.counter-widget--horizontal input, .counter-widget--horizontal li {
float: left;
}
.counter-widget--horizontal input {
width: 33.33%;
box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.1);
border: none;
}
.counter-widget--horizontal li {
width: 50%;
}
.counter-widget--horizontal input, .counter-widget--horizontal a {
font-size:...
JavaScript
/*Simple Counter Demo*/
$('.plus-minus-btn').click(function (e) {
var $button = $(this);
var oldValue = $("#clickCount").val();
if ($button.text() == "+") {
var newVal = parseFloat(oldValue) + 1;
} else {
// Don't allow decrementing below zero
if (oldValue > 0) {
var newVal = parseFloat(oldValue) - 1;
} else {
newVal = 0;
}
}
$("#clickCount").val(newVal);
e.preventDefault();
});