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

165
Vistas
How to limit the amount of times the element is generated

I have this code that displayes the products alongside their price. The problem is that every time I go back and forward the price is added again. project itself is created through .js files so the url code doesn's change if that information helps.

function(val) {
  var products = $('#products');
  var children = products.children('#productsUserInputs').children();
  for (var i = 0; i < children.length; i++) {
    var current = children[i];
    var currentId = $(current).attr('id').toLowerCase();
    var result = val.map(a => (a.Product + 'wrapper').toLowerCase());
    var productName = currentId.replace('wrapper', '');
    var foundProduct = val.find(e => e.Product.toLowerCase() === productName);
    if (foundProduct) {
      var price = foundProduct.Price;
      var priceDisplay = document.createElement("div");
      var priceId = priceDisplay.setAttribute('id', 'price');
      priceDisplay.append(price);
      current.appendChild(priceDisplay);
      var getprice = document.getElementById('price');
      if (getprice > 1) {
        priceDisplay.setAttribute("class", "hidden");
      } else {
        priceDisplay.setAttribute("class", "display-price");

      }

    }

    if (result.includes(currentId)) {
      $(current).attr("hidden", false);

    } else {
      $(current).attr("hidden", true);


    }

    if (result.includes(!priceDisplay)) {
      $(priceDisplay).attr("hidden", true);
    } else {
      $(priceDisplay).attr("hidden", false);
    }
  }
}

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