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

107
Visualizações
.each loop is not working in my jQuery code

The code below is written to hide the "IN STOCK" phrase on certain vendors' product pages. I noticed the loop itself isn't running when I used console.log. Could you please help correct the code?

function runPmmCustomAllPagesJs($) {
    // This function is called from argento-custom.js once dom is ready and jQuery obect is available.
    // $ has the jQuery object.

    var docloch = document.location.href,
        scree = [screen.availWidth, screen.availHeight],
        thisVal = "",
        tAlign = "left",
        afterwhat = "h3",
        df,
        hide_inStock= [':"JV', ':"KE', ':"MB', ':"WD'],
        doc_text=$(document).text(),
        v_code;
        
        
    // hides the "IN STOCK" phrase on certain vendors' product pages
    $(hide_inStock).each(function(v_code){
        console.log('v_code: ' + v_code);
        if (doc_text.indexOf(v_code)>1){
            $(".stock").hide();
            return false;
        }
    });
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When false is returned from the predicate, the iteration is ended prematurely. Return something else or even nothing if you want it to get to the end.

Also, remember that the first argument passed to .each is the index.

$([1, 2, 3]).each((_index, value) => {
    console.log(value);

    if (value === 2) {
        return false;
    }
});
// 1
// 2
about 4 years ago · Juan Pablo Isaza Relatório
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