Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!