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

145
Views
Get the id of the parent (li) with its content (span). CHEERIO

I have a code here which I got by scraping a page:

<div>
    <ul id="options">
        <li id="option-1" data-nume="1">
            <span class="title">Book</span>
            <span class="site">fnac.com</span>
        </li>
        <li id="option-2" data-nume="2">
            <span class="title">TV</span>
            <span class="site">youtube.com</span>
        </li>
    </ul>
</div>

And I would like with cheerio or just Vanilla JS to find the id of the parent (li) with its content (span).

Example:

  • Detect the span element TV
  • Take the id of its parent (here option-2)
  • Return the value data-nume.

Thank you in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try using filter()

https://api.jquery.com/filter/#filter-selector

const $tv = $('#options .title').filter(function() {
  return $(this).text().trim().toLowerCase() === 'tv';
});

const tvNume = $tv.parent('[data-nume]').data('nume');

console.log(tvNume);

Working Demo

https://codesandbox.io/s/ecstatic-tree-6hez6?file=/src/index.js

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!