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

301
Visualizações
how to get value from the right class if class is included several times

How do I get the correct value of a class, if the class name is included several times? I have this structure on a webpage and the value I need is always inside the div "auctionValue" and there in "curreny-coins value" ("5,500" in this example) but this class name ""curreny-coins value" is available 60 times on that page. And I only need the value from "auctionvalue" -> "currency-coins value":

enter image description here

How can I access this specific class value inside class "auctionValue" and not get all 60 values as a result for example from "auctionStartPrice"? I tried this:

let currencyValues = [];
function highlightDeal() {
    let currentBid = document.getElementsByClassName('currency-coins value');
    for (i = 0; i < currentBid.length; i++) {
        currencyValues.push(currentBid[i].innerHTML);
    }
    console.log(currencyValues);
}

highlightDeal();

but it logs an array of all 60 values with that class name.

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

0

You can target the second child using nth-child selector:

document.querySelector(".auction > .auctionValue:nth-child(2) > .currency-coins.value")

Demo:

const bid = document.querySelector(".auction > .auctionValue:nth-child(2) > .currency-coins.value").textContent;

console.log(bid);
<div class="auction">

  <div class="auctionValue">
  </div>
  
  <div class="auctionValue">
    <span class="currency-coins value">5,500</span>
  </div>
  
  <div class="auctionValue">
  </div>

</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

1. Please copy the query selector of the specific element in inspector.

enter image description here

2. And paste it into below code.

const currentBid = document.querySelector("body > main > section > section > div.ut-navigation-container-view--content > div > div > section.ut-pinned-list-container.SearchResults.ui-layout-left > div > ul > li.listFUTItem.has-auction-data.selected > div > div.auction > div:nth-child(2) > span.currency-coins.value").textContent;
console.log(currentBid);
about 4 years ago · Juan Pablo Isaza Relatório

0

In addition to the answer from Mamun to get all values on that page: (example code)

function get42() {
    var tds = document.querySelectorAll('td'),
        result = [];
    for (var i = 0; i < tds.length; i++) {
        result.push(tds[i].textContent);
    }
    return result;
}
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