Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

68
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');
                }
            });
    
7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.