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

243
Vistas
how can I change the text of the button

I need to change the text of the button after the success adding to the basket. But it change it just after the second click. How can I change it if Im using foreach in php

<td>
<?if(count($arElement["OFFERS"]) > 0):?>
    <?foreach ($arElement["OFFERS"] as $offer): ?>
        <?//var_dump($offer["ID"]);?>
        <div class="button456" >
            <button class="button-offer" id="but123" onclick="add2basket(<?=$offer["ID"]?>)">To the basket</button>
    <?endforeach?>

<?else:>
    <button class="button-simple" id="but1234" data-id="12345" onclick="add2basket(<?=$arElement["ID"]?>)">To the basket</button>
<?endif?>
        </div>
</td>
<script type="text/javascript">
function add2basket(ID) {
    $.ajax({
        type: "POST",
        url: "/ajax/add_tobasket.php",
        dataType: 'html',
        data: {PRODUCT_ID: ID,QUANTITY: $(".quantity" + ID).val(),},
        success: function (html) {
            $('button').on('click', function(){
                $(this).closest('button').text("In the basket");
            });
        },
    });
}
about 4 years ago · Santiago Trujillo
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