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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:08:16+00:00 2026-06-13T23:08:16+00:00

I am binding a function to an html element. there is some data in

  • 0

I am binding a function to an html element.

there is some data in loop which is changing on each iteration

data = {
    networkId: networkId,
    network_avatar: network_avatar,
    network_user_name: network_user_name,
}

Here I am binding it:

$("#element"+i).bind(function(){ 
    change(data);
}

The function is:

function change(data){
    console.log(data);
}

There should be the different data in data variable on each iteration.

But the it always contains the content of last iteration.
Why jQuery changes the data that is already binded with change() function

  • 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-13T23:08:16+00:00Added an answer on June 13, 2026 at 11:08 pm

    First of all, don’t use global variables named “data” or “window” or anything else like this. If the declaration of your variable data is somewhere in vision area use “var” bareword.

    When the event handler is called, it calls the “change” function and sending the current value of data in it. What you need, is to declare own data for each handler. And you should use “var” for it. Like:

    $("#element"+i).bind(function(){
       var currentDataValue = new CopyData(data);
       change(currentDataValue);
    }
    
    function CopyData(object) {
       var data = {};
       for (var val in object)
          data[val] = object[val];
       return data;
    }
    

    I guess it should help. But i’m not too sure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so im using a simple submit binding to pass a function data: <form data-bind=submit:
I'm binding some slightly complex functionality to a click event $(someSelector)).bind('click', someFunction(a,b,c)); function somefunction(a,b,c)
I have this HTML element: <div id='4-12-2012' class='date'>blah blah blah</div> And I'm binding a
How can I change the click binding of an element? Html snippet is: <div
I want to render some json data using HTML template. I haven't started implementing
I'm binding a click event to a div element, which is created after clicking
(defun foo () message hello) I want to binding the function foo to key
I am asking about the static binding of the function in C++. What's the
I'm binding events to a container div with jQuery's on() function and supplying a
Suppose I have a <select> element on my HTML page, and I want to

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.