Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

161
Visualizações
How to pluralize a label based on a number input

I have a number input controlled by (+) and (-) buttons. I added a unit label after the number with a span following the input, but now am having trouble figuring out how to pluralize the unit when you increase the number from 1 item --> 2 items

Is there an easy way to do this? (i'm a beginner)

    

$(document).ready(function() {
  $(".panel-calc").on("input", ".quantity", function() {    
    
  var quantity = +$(this).val();

  })
  
  var $buttonPlus = $('.plus-button');
  var $buttonMin = $('.minus-button');
  var $quantity = $('.quantity');

  /*For plus and minus buttons*/
  $buttonPlus.click(function() {
    $quantity.val(parseInt($quantity.val()) + 1).trigger('input');
  });

  $buttonMin.click(function() {
    $quantity.val(Math.max(parseInt($quantity.val()) - 1, 1)).trigger('input');
  });
})
.widget {
  text-align: center;
  padding: 40px;
}

input {
  text-align: center;
  width: 40px;
  border: none;
  text-align: right;
}

.label {
  padding-right: 35px;
  font-family: sans-serif;
  font-size: 13px;
}
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>


<div class="widget">

<! --- plus minus interactive ---> 
<button type="button" class="minus-button">-</button>
  <input type="text" class="quantity" value="1"><span class="label"> item</span>
  <button type="button" class="plus-button">+</button>
  
</div>

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda