Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
Cómo agrupar elementos con JQuery según niveles

Quiero agrupar el siguiente html:

 <h2>Summarize the problem<h2> <h3>Include details about your goal<h3> <h3>Include details about your goal<h3> <h3>Include any error messages<h3> <h2>Describe What you have tries<h2> <h3>Show what you've tried and tell us what you found<h3> <h3>Lorem Ipsum LOL<h3> ...

dentro

 <div> <h2>Summarize the problem</h2> <h3>Include details about your goal</h3> <h3>Include details about your goal</h3> <h3>Include any error messages</h3> </div> <div> <h2>Describe What you have tries</h2> <h3>Show what you've tried and tell us what you found</h3> <h3>Lorem Ipsum LOL</h3> </div>

lo que he probado

Intenté recorrer todos los elementos, pero nunca funcionó. No estoy poniendo el código aquí porque descubrí que ni siquiera tiene sentido

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Aquí hay una versión de trabajo.

 $("h2").each(function() { const $this = $(this) const $h3 = $this.nextUntil("h2"); // find all tags until next H2 $this .wrap('<div class="wrapper" />') .after($h3) })
 .wrapper { border: 1px solid black }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <h2>Summarize the problem</h2> <h3>Include details about your goal</h3> <h3>Include details about your goal</h3> <h3>Include any error messages</h3> <h2>Describe what you have tried</h2> <h3>Show what you've tried and tell us what you found</h3> <h3>Lorem Ipsum LOL</h3>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda