JSFiddle - React, Tailwind, and code Playground

by Luis Carlos Carvalho

HTML

<div class="qty">
    <button class="btqtd">-</button>
    <input type="text" name="qtd" id="123" class="qtd" value="1">
    <button class="btqtd">+</button>
</div>

JavaScript

$(document).ready(function() {
    $(".btqtd").on("click", function() {

        var $button = $(this),
            $input = $button.closest('.qty').find("input.qtd");
            //$idInput = ;
        var oldValue = $input.val(),
            newVal;
        if ($.trim($button.text()) == "+") {
            newVal = parseFloat(oldValue) + 1;
        } else {
            if (oldValue > 1) {
                newVal = parseFloat(oldValue) - 1;
            } else {
                newVal = 1;
            }
        }
        $input.val(newVal);
    });
});