[jQuery] Dynamically added click registration always returns the last value added

2006-12-13 Thread leftend
Hello, I'm parsing this JSON: {result:success,successText:Your changes have been saved successfully.,errorText:,memberID:49,mode:edit,jobs:[{jobID:1,companyName:SAIC},{jobID:2,companyName:Aspentech},{jobID:3,companyName:Cardinal Health}]} ...with this Javascript:

Re: [jQuery] Dynamically added click registration always returns the last value added

2006-12-13 Thread leftend
The a tag that was in the var div line got rendered as an actual link. Here it is again with spaces to prevent it from being rendered as a link: var div = div id='job + j.jobID + 'h1 id='jobTitle + j.jobID + ' style='display:inline;font-weight:normal' + j.companyName + /h1nbsp;| a href='#'

Re: [jQuery] Dynamically added click registration always returns the last value added

2006-12-13 Thread Michael Geary
You're using the variable j to hold a reference to each element of the jobs array as you go through the loop. After the loop finishes, j is a reference to the last element of that array. Later, when the click function gets called, j still refers to that last element - regardless of which element

Re: [jQuery] Dynamically added click registration always returns the last value added

2006-12-13 Thread leftend
Wow, thanks very much. It worked like a charm. I hadn't used the $.each function in jQuery yet, so thank you for pointing me to it. I suspect I'll be using it a lot more now that I know how to! Chad Michael Geary wrote: You're using the variable j to hold a reference to each element of