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

154
Visualizações
How to triger button onclick on a tag

I have one anchor tag and a button inside the same div parent.

Clicking on an anchor need to click the button too via code.

Below is my HTML

<div class="product_list">
    <a class="action tocart primary new_add_to_cart"><span>Add to cart</span></a>
    <button type="submit" id="product-addtocart-button-927" title="Add to Cart" class="main-add-tocart action tocart primary">
        <span>Add to cart</span>
    </button>
</div>
<div class="product_list">
    <a class="action tocart primary new_add_to_cart"><span>Add to cart</span></a>
    <button type="submit" id="product-addtocart-button-928" title="Add to Cart" class="main-add-tocart action tocart primary">
        <span>Add to cart</span>
    </button>
</div>

Below is the JavaScript code I tried to use

$(document).on('click','.new_add_to_cart',function(){
    var pin = $.cookie('delivery-pincode');
    if(!pin){
        alert("hii2");
    }
    else{
        $(this).closest(".main-add-tocart").trigger("click");
    }
});

In the else condition I want the closest button (sibling) to be clicked, I have multiple product(parent divs with the same class .product_list) and I want only click only on the "current" product.

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