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

268
Views
How to take div value through parent elements using jquery?

I need to take the text "UNIT01". How I can do this using JQuery or JS?

`<div id="unit">
 <ul class="choices">
   <li>
    <div>UNIT01</div>
   </li>
   <li>
    <div>UNIT02</div>
   </li>
 </ul>
</div>`
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

$( document ).ready(function() {
var txt = $('.choices li:first-child>div').text()
console.log( txt );});
over 4 years ago · Santiago Trujillo Report

0

This code will access the text inside that div by accessing the div through its parent elements.

var unit = document.getElementById("unit");
var list = unit.getElementsByTagName("ul")[0];
var items = list.getElementsByTagName("li")[0];
var div = items.getElementsByTagName("div")[0];
var text = div.innerHTML;
alert(text);
<div id="unit">
  <ul class="choices">
    <li>
      <div>UNIT01</div>
    </li>
    <li>
      <div>UNIT02</div>
    </li>
  </ul>
</div>

over 4 years ago · Santiago Trujillo 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!