• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home » Resolved: Get child nodes

Resolved: Get child nodes

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have this code
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

Answer:

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

If you have better answer, please add a comment about this, thank you!

children css html javascript
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to resolve LNK2001 in c++ projects

26/03/2023

Resolved: How to correctly initialize vector of number in Typescript

26/03/2023

Resolved: mysql calculating to get profit or loss from 2 tables ( Purchases and Sales) in FIFO mode

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.