Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:02:48+00:00 2026-06-08T21:02:48+00:00

This is actual code, how do I pass list[i].fnctn correctly to the click handler?

  • 0

This is actual code, how do I pass list[i].fnctn correctly to the click handler?

list[i].fnctn – Contains the name of the function that I want to attach to the click event handler.

function createList(list){
    var parentID = $("#content_nav ul");
    var len = list.length;
    for(var i=0;i<len;i++){
        var anchorElement = jQuery('<a />',{text:list[i].text});
        var liElement = jQuery('<li />',{"class":"navlink_"+(i+1),id:"navlink_"+(i+1)});
        //anchorElement.attr('onclick',list[i].fnctn+"()"); - Works fine on desktop browsers but doesn't work on mobile devices. (Mobile devices are my target platform

        anchorElement.on('click',function(event) {
            return window[list[i].fnctn](event); // Here I am getting the error - cannot access property fnctn of undefined
        });
        liElement.append(anchorElement);
        parentID.append(liElement);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:02:49+00:00Added an answer on June 8, 2026 at 9:02 pm

    Would that help, I am not sure if this is possible with the .on() method.

    var message = 'Some value that I want to access inside handler function';
    
    
    $('#myHandler').click({msg: message},function(e){
        alert(e.data.msg);
    });
    

    Edited:

    As xiaowl mentioned. Changing my code for your scenario.

    function myFunction(){
        var message= "Some value that I want to access inside handler function";
        $("#myHandler").on('click', {msg: message}, function(e){
            alert("I want to alert the value - " + e.data.msg);
        });
    }
    

    For the actual Condition

    function createList(list){
        var parentID = $("#content_nav ul");
        var len = list.length;
        for(var i=0;i<len;i++){
            var anchorElement = jQuery('<a />',{text:list[i].text});
            var liElement = jQuery('<li />',{"class":"navlink_"+(i+1),id:"navlink_"+(i+1)});
            anchorElement.on('click',{myFunction: list[i]}, function(event) {
                return window[event.data.myFunction](event);
            });
            liElement.append(anchorElement);
            parentID.append(liElement);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Full disclosure: this is for an assignment, so please don't post actual code solutions!
Note, this isn't my code, or the actual code in the form. This is
This is not an actual Xcode error message, it is a warning that has
I have this webservice snippet and i want to print the actual value returned.
I was browsing the Django source code and I saw this function: def colorize(text='',
excuse the pseudo code, my actual file is much larger:/ I want to call
This is the actual error message i'm getting if i run it on an
This is more of a theoretical question than an actual problem I have. If
Disclaimer: this question is driven by my personal curiosity more than an actual need
I'm wondering what the actual reason is why you can do this on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.