Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda