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

192
Views
How to get last child from parent element using query selector method?

For example:

<div class="list-container">
  <p>hello<p>
  <p>hello<p>
  <p>hello<p>
  <p>hello<p>
</div>

How to get that last child element? I would like to point out that the children elements are dynamically created and keep increasing or decreasing according to the user's whim. And I want to be able to pick the last child every time this happens. That's why I ask. Plz, share me the syntax. Thank you.

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

0

.list-container > p:last-child will do

And please, avoid bloatware, such as jquery...

console.log(document.querySelector(".list-container > p:last-child"));
<div class="list-container">
  <p>hello1</p>
  <p>hello2</p>
  <p>hello3</p>
  <p>hello4</p>
</div>

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!