Click here to Skip to main content
15,896,557 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Reading XML - success being ignored Pin
Jasmine250121-May-13 7:23
Jasmine250121-May-13 7:23 
GeneralRe: Reading XML - success being ignored Pin
Dennis E White21-May-13 8:02
professionalDennis E White21-May-13 8:02 
AnswerRe: Reading XML - success being ignored Pin
Jasmine250121-May-13 6:02
Jasmine250121-May-13 6:02 
GeneralRe: Reading XML - success being ignored Pin
#realJSOP21-May-13 6:55
professional#realJSOP21-May-13 6:55 
GeneralRe: Reading XML - success being ignored Pin
Jasmine250121-May-13 7:21
Jasmine250121-May-13 7:21 
GeneralRe: Reading XML - success being ignored Pin
#realJSOP21-May-13 8:55
professional#realJSOP21-May-13 8:55 
Questionproblem with JQuery. Pin
imbaro20-May-13 4:25
imbaro20-May-13 4:25 
AnswerRe: problem with JQuery. Pin
Richard Deeming20-May-13 4:47
mveRichard Deeming20-May-13 4:47 
The function you've passed to the .click method has captured a reference to the variable, not the value of the variable. The usual C# approach of creating a copy of the variable within the loop won't work, since JavaScript variables are function-scoped.

Try something like this:
JavaScript
var handlerFactory = function(tmp){ return function() { func(tmp); } };

$ParentObject = $("<div id=\"Parent\"></div>");
for (var i=0; i < 10; i++)
{
    $ChildObject = $("<div id=\"child" + i + "\"></div>");
    $ChildObject .click(handlerFactory(i));
    $ParentObject.append($ChildObject);
}


(Based on this SO answer[^].)



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: problem with JQuery. Pin
imbaro20-May-13 4:54
imbaro20-May-13 4:54 
QuestionAccount delete! Pin
Hakan Bulut18-May-13 2:14
Hakan Bulut18-May-13 2:14 
AnswerRe: Account delete! Pin
dusty_dex18-May-13 2:52
dusty_dex18-May-13 2:52 
GeneralRe: Account delete! Pin
Hakan Bulut18-May-13 3:07
Hakan Bulut18-May-13 3:07 
GeneralRe: Account delete! Pin
dusty_dex18-May-13 4:42
dusty_dex18-May-13 4:42 
AnswerRe: Account delete! Pin
Thomas Daniels18-May-13 4:53
mentorThomas Daniels18-May-13 4:53 
QuestionHow to show long message in pop up Pin
InderK16-May-13 21:56
InderK16-May-13 21:56 
QuestionScrollbar in div Pin
InderK16-May-13 4:01
InderK16-May-13 4:01 
AnswerRe: Scrollbar in div Pin
ZurdoDev21-May-13 10:32
professionalZurdoDev21-May-13 10:32 
Questionhow to access datasource for ListDropDown in java script Pin
mhd.sbt13-May-13 9:16
mhd.sbt13-May-13 9:16 
AnswerRe: how to access datasource for ListDropDown in java script Pin
Dennis E White13-May-13 18:29
professionalDennis E White13-May-13 18:29 
AnswerRe: how to access datasource for ListDropDown in java script Pin
dusty_dex15-May-13 13:36
dusty_dex15-May-13 13:36 
GeneralRe: how to access datasource for ListDropDown in java script Pin
Dennis E White15-May-13 18:26
professionalDennis E White15-May-13 18:26 
GeneralRe: how to access datasource for ListDropDown in java script Pin
dusty_dex15-May-13 23:14
dusty_dex15-May-13 23:14 
GeneralRe: how to access datasource for ListDropDown in java script Pin
Dennis E White16-May-13 4:04
professionalDennis E White16-May-13 4:04 
GeneralRe: how to access datasource for ListDropDown in java script Pin
Dennis E White16-May-13 4:09
professionalDennis E White16-May-13 4:09 
GeneralRe: how to access datasource for ListDropDown in java script Pin
dusty_dex16-May-13 4:31
dusty_dex16-May-13 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.