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

313
Views
jQuery: Accessing text content of descendant upon clicking
<div class="subjects">
  <div class="bg-red">
    <i class="lni lni-rocket"></i>
    <h6 class="font-weight-bold">Physics</h6>
  </div>
</div>

Say I have the above html, and I would like to get the text content of h6 every time I click the outermost div. Here's what I did:

$('.subjects').on('click', (e) => {
    const h6 = $(this).find('h6');
    console.log(h6.text());
});

But this does not print Physics, which was inside h6. It print's an empty string. How do I access the text of h6 when I click the outermost div?

about 4 years ago · Juan Pablo Isaza
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!