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 6158819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:01:32+00:00 2026-05-23T21:01:32+00:00

var DAYBOOK = { 22 : ‘hmm’, 9 : ‘waaaah’ }; function cnstr_submenu(){ var

  • 0
var DAYBOOK = {
    22 : 'hmm',
    9 : 'waaaah'
};

function cnstr_submenu(){
    var elm = $('#test');
    for(var key in DAYBOOK){
        (function(key){
            elm.append('<a href="#">'+DAYBOOK[key]+'</a><br>').click(function(){
                alert(key);
            });
        })(key);
    }
};
cnstr_submenu();

http://jsfiddle.net/9AqVK/

Why is it that all properties in the DAYBOOK object is alerted when you click a link?

  • 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-05-23T21:01:32+00:00Added an answer on May 23, 2026 at 9:01 pm

    elm.append(...).click will in fact bind the click to the elm (the div). So when clicking a link, the link doesn’t do much – rather the click handlers of the div are executed, which has had a function bound for click twice.

    If you want each link to alert one value, bind the function to the link instead:

    elm.append( // append the following element
        // create a link with a click handler bound
        $('<a href="#">'+DAYBOOK[key]+'</a><br>').click(function(){
                alert(key);
        })
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var thumbs = document.getElementsByTagName(img); for (var i=0; i<thumbs.length; i++) { Core.addEventListener(thumbs[i], click, function() {alert(i);});
var dlg = $(#dialog).dialog({ autoOpen: false, modal: true, buttons: { 'Update': function() { alert(clientCode);
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();
var results = ['one', 'two', 'one hundred', 'three']; var removal = []; $.each(results, function(i)
var foo = 'hello'; var myfunc = function() { console.log(foo); var foo = foo
var dateRegex = /\/Date\((\d+)\)\//g; // [0-9] instead of \d does not help. dateRegex.test(/Date(1286443710000)/); //
var request = new Request({ method: 'get', url: 'onlinestatusoutput.html.php', onComplete:function(response) { $('ajax-content').get('tween', {property: 'opacity',
var input; // method 1 input = document.getElementById('address').value; alert(input) // method 2 eval('input =
var plugin = { Init: function() { this.UpdateUI(); if (this.Status() == 1) { ...
var MyObj = function(h,w){ this.height = h; this.width = w; } I would like

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.