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

199
Visualizações
Hello. Why "display none" is not applied

I want to hide the block where id ends with _event_2 or _event_1. https://i.stack.imgur.com/8pVff.png I slightly corrected the code.

let tabMyMarketHistory = document.getElementsByClassName("market_tab_well_tabs")[0];
let aDisplayNoneListing = document.createElement('a');
let spanDisplayNoneListing = document.createElement('span');
aDisplayNoneListing.id ="displayNoneListingCanceledCreated";
aDisplayNoneListing.className ="market_tab_well_tab";
spanDisplayNoneListing.className ="market_tab_well_tab_contents";
spanDisplayNoneListing.textContent ="Clear";
aDisplayNoneListing.append(spanDisplayNoneListing);
tabMyMarketHistory.append(aDisplayNoneListing);

let DisplayNoneListing =document.getElementById("displayNoneListingCanceledCreated");
DisplayNoneListing.onclick = function() { 
    DisplayNoneListing.className = "market_tab_well_tab market_tab_well_tab_active";
    let itemDetals =document.querySelectorAll(`div[id^="history_row"]`);
    if (itemDetals.length > 0) {
        for (let i= 0; i < itemDetals.length; i++) {
            if (itemDetals[i].id.includes('event_1') || itemDetals[i].id.includes('event_2')) {
                document.getElementById(itemDetals[i].id.toString()).style.display = 'none';
                console.log(document.getElementById(itemDetals[i].id.toString()));
            }
        }
        
    }
};
        
    }

Thank you very much for your comments.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It works for me, it is hidden, but not without when I delete the 1 from the end of the ID:

let itemDetals = document.querySelectorAll(`div[id^="history_row"]`);
if (itemDetals.length > 0) {
  for (let i = 0; i < itemDetals.length; i++) {
    if (itemDetals[i].id.includes('_event_1') || itemDetals[i].children[6].firstElementChild.id.includes('_event_2')) {
        document.getElementById(itemDetals[i].id.toString()).style.display = 'none';
        console.log(itemDetals[i].id.toString());
    }
  }
}
<div class="market_listing_row market_recent_listing_row" id="history_row_3297188894015887588_event_1">Hi</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Not really sure what you're trying to accomplish with the following line. Can you explain it?

itemDetals[i].children[6].firstElementChild.id.includes('_event_2')

I changed it to look for event_2 just like the first one like I thought and it works fine, even on children of the div (if that is what you were trying to accomplish, that's my guess). You basically target all divs in the DOM whether they are children or not.

PS: Two small nitpicks. You should rename detals to details (misspelling error) and change the includes to only look for event_1 or event_2, since the extra _ is kind of unnecessary.


Here's the code:

<html>
    <body>
        <div class="market_listing_row market_recent_listing_row" id="history_row_3297188894015887588_event_3">
            Event 3 - Parent
            <div class="market_listing_row market_recent_listing_row" id="history_row_329718889ee4015887588_event_2">Event 1 - Child</div>
        </div> 
        <div class="market_listing_row market_recent_listing_row" id="history_row_3297188894015887588_event_1">
            Event 1 - Parent
            <div class="market_listing_row market_recent_listing_row" id="history_row_329714015887588_event_2">Event 2 - Child</div>
        </div> 

        <script>
            let itemDetals = document.querySelectorAll(`div[id^="history_row"]`);
            if (itemDetals.length > 0) {
                for (let i= 0; i < itemDetals.length; i++) {
                    if (itemDetals[i].id.includes('event_1') || itemDetals[i].id.includes('event_2')) {
                        document.getElementById(itemDetals[i].id.toString()).style.display = 'none';
                    }
                }
            }
        </script>
    </body>
</html>

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