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

183
Vistas
How can i add a class e.g 'active' in one of these < li >, one at a time with up and down key press?

I tried making a pointer to first li and then tried navigating through it but not working in my case: [this is the pic of my dom element ][1]

  [1]: https://i.stack.imgur.com/f1uO6.png   

Code:

 $(window).keyup(function(e) {
                console.log("Key Code: ", e.keyCode);
                var $currentParent = $('div[data-tree-model] li.active');
                console.log("Current Parent", $currentParent);
                var $next;
                if (e.keyCode === 39 || e.keyCode === 37) {
                    $currentParent[0].firstElementChild.click();
                   
                } else if (e.keyCode == 38) {
                    $next = $currentParent.prev();
                } else if (e.keyCode == 40) {
                    $next = $currentParent.next();
                }

                if ($next.length > 0) {
                    $('div[data-tree-model] li ').removeClass('active');
                    $next.addClass('active');
                }
            });
    
about 4 years ago · Juan Pablo Isaza
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