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

185
Views
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
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!