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

212
Vistas
Get child nodes

I have this code

<div id="page1-div" style="position:relative;width:1347px;height:1189px;">
        <img width="1347" height="1189" src="target001.png" alt="background image" />
        <p style="position:absolute;top:218px;left:209px;white-space:nowrap" class="ft10">Mario</p>
        <p style="position:absolute;top:218px;left:263px;white-space:nowrap" class="ft10">Lopez</p>
        <p style="position:absolute;top:218px;left:827px;white-space:nowrap" class="ft10">18987456O</p>
        <p style="position:absolute;top:395px;left:183px;white-space:nowrap" class="ft10">25</p>
        <p style="position:absolute;top:395px;left:402px;white-space:nowrap" class="ft10">Fisica y Química</p>
        <p style="position:absolute;top:433px;left:298px;white-space:nowrap" class="ft10">Ninguna</p>
        <p style="position:absolute;top:502px;left:633px;white-space:nowrap" class="ft10">230</p>
</div>
<div id="page2-div" style="position:relative;width:1347px;height:1189px;">
        <img width="1347" height="1189" src="target002.png" alt="background image" />
        <p style="position:absolute;top:149px;left:300px;white-space:nowrap" class="ft20">25</p>
        <p style="position:absolute;top:149px;left:565px;white-space:nowrap" class="ft20">Fisica y Química</p>
        <p style="position:absolute;top:149px;left:984px;white-space:nowrap" class="ft20">fevev</p>
        <p style="position:absolute;top:172px;left:425px;white-space:nowrap" class="ft20">fevevvvev</p>
        <p style="position:absolute;top:172px;left:912px;white-space:nowrap" class="ft20">Juan Soler</p>
        <p style="position:absolute;top:195px;left:319px;white-space:nowrap" class="ft20">Ana&#160;Abarca</p>
        <p style="position:absolute;top:195px;left:981px;white-space:nowrap" class="ft20">9:30-14:30</p>
</div>`

I want to get all p elements inside both divs to set different id attributes (or change the values of the class attributes if that is easier) to each of them so I can modify the styles in a css file. But I don´t know how to properly access the p elements inside the two divs

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You would need to get the div elements, then on those elements, you can do querySelectorAll('p') to get an array of the paragraphs.

Something like this.

const firstDiv = document.querySelector('#page1-div')
const firtDivParagraphs = firstDiv.querySelectorAll('p')

If you just want to get all the paragraphs and you don't care about where they are you can of course query them on the document object instead. You could also be more generic to access all paragraphs following div's:

const paragraphs = document.querySelectorAll('div > p')

Essentially any valid CSS selector can be used with querySelector or querySelectorAll.

Without knowing what exactly you are trying to do, it would probably be better using classes for the divs, then you could query them at the same time, instead of having to query them separately.

const paragraphs = document.querySelectorAll('.div-class > p')
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