Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

teampoison's avatar

when quantity is 1 then decrease quantity button hide

i create a quantity button on starting its showing one plus sign when user increase value than decrease button are showing but when its equal to one decrease button are still showing. I want if quantity is equal to one minus button are hide.

 <div class="quantity-margin">
               {% if product.tags contains 'cost-per-letter' %}
               <div style="display:none;" class="dec button">-</div>
              <input  style="display:none;" type="text" id="quantity" name="quantity" value="1">
              <div  style="display:none;"  class="inc button">+</div>
              {% else %}
           <div class="dec button" id="minus-button" style="display:none;">-</div>
              <input type="text" id="quantity" name="quantity" value="1">
              <div class="inc button product-plus-button">+</div>
              {% endif %}
              <script>
                $(function () {
        $(".product-plus-button").on('click', function () {
            $("#minus-button").show();
        });
    });
              $('#minus-button:value(1)').hide();

               
                </script>

0 likes
5 replies
nikulpaladiya's avatar

Hello @teampoison

add $('#minus-button:value(1)').hide(); Instead of if($('#quantity').val() == 1){ $("#minus-button").hide(); }

let's see if it will work.

teampoison's avatar

@nikulpaladiya where i add this code

<div class="dec button" id="minus-button" style="display:none;">-</div>
              <input type="text" id="quantity" name="quantity" value="1">
              <div class="inc button product-plus-button">+</div>
              {% endif %}
              <script>
                $(function () {
        $(".product-plus-button").on('click', function () {
            $("#minus-button").show();
                $('#minus-button:value(1)').hide();
        });
    });
                </script>
nikulpaladiya's avatar
Level 6

@teampo Remove or comment on your script and add this

$(function () { $(".product-plus-button").on('click', function () { $("#minus-button").show(); }); $("#minus-button").on('click', function () { let quantity = $('#quantity').val(); if(quantity == 1) { $("#minus-button").hide(); } }); });

Hope so, it will work

Please or to participate in this conversation.