Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda