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

212
Views
e is undefined, correct syntax for a recursive handler function

How to make a correct recursive call? In this code the console says me "e is undefined". It's a event listener for a button ul in a unordered list.

This is my code:

$("button#ul").on("click", function(event){
    
     var button = $(this);
        $(button).toggleClass("active");
        
        if ($(button).hasClass('active')){


    //event listener
        $(document).on("keydown", **checkExit** = function(e) {
                                            
                            if (exit(e) == true){
                                $(button).removeClass('active');
                                $(this).off("keydown");
                            }
                            **checkExit();**
                       });
    
    
    
    
    
    function exit(event){
            
    //        alert("prevKeyCode: "+prevKeyCode);
            var code = event.keyCode || event.which;
            var doubleEnter = (code == 13 && prevKeyCode == code);
            
            if (event.type == "click"){
                return true;
            }
            else if (event.type == 'keydown'){
                
                
                if (code == 27 || doubleEnter) {
                    prevKeyCode = null;
                    return true;
                }
                else if (code == 13) {
                    prevKeyCode = 13;
                }
                else {
                    prevKeyCode = code;
                }
                return false;
            }
        }
        

I think I should define outside the function checkExit...

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to pass the event as a parameter when calling checkExit again:

$(document).on("keydown", checkExit = function(e) {
  if (exit(e) == true) {
    $('button').removeClass('active');
    $(this).off("keydown"); //spegne il gestore corrente
  }
  checkExit(e);
});
about 4 years ago · Juan Pablo Isaza 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!