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

272
Views
¿Cómo tomar el valor div a través de elementos principales usando jquery?

Necesito tomar el texto "UNIT01". ¿Cómo puedo hacer esto usando JQuery o 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

Este código accederá al texto dentro de ese div accediendo al div a través de sus elementos principales.

 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!