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

143
Views
Obtenga la identificación del padre (li) con su contenido (span). CHEERIO

Tengo un código aquí que obtuve raspando una página:

 <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>

Y me gustaría con cheerio o simplemente Vanilla JS encontrar la identificación del padre (li) con su contenido (span).

Ejemplo:

  • Detectar el elemento de tramo TV
  • Tome la identificación de su padre (aquí opción-2 )
  • Devuelve el valor número-datos .

Gracias de antemano.

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

0

Intenta usar 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);

Demostración de trabajo

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!