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

217
Views
JS/jQuery: ¿Obtener la profundidad del elemento?

¿Cuál es la forma más fácil de obtener la profundidad de un elemento en JavaScript puro o jQuery? Por "profundidad" me refiero a cuántos elementos de profundidad está anidado o cuántos ancestros tiene.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Qué tal si:

 $('#my-element').parents().length
over 4 years ago · Santiago Trujillo Report

0

Una nota adicional. Si desea obtener la profundidad relativa a un determinado contexto, puede hacerlo:

 var depth = $("#my-element","#ContextContainerID").parents("ul").length;

Arriba, estoy buscando cuántos UL hay dentro del contenedor #ContextContainerID

over 4 years ago · Santiago Trujillo Report

0

Supongamos que no desea incluir el cuerpo y la etiqueta html en los padres para contar el uso:

 $("#element").parents("*").not("body,html").size()

Demostración en línea aquí: http://jsfiddle.net/zaJff/

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!