Hi hedgomatic, I just noticed something about your code, in the highlighted line, I think it should be elements.push(wordsSelected+','); instead of Array.push(wordsSelected+','); I tried the code like that and it works for me. Thanks Qutoz.
$(".button").click(function() { elements = new Array(); $(".elementSelected").each(function() { var wordsSelected = $(this).html(); // this is probably wrong. Array.push(wordsSelected+','); $alert(elements); //debug }); }); On Thu, Apr 3, 2008 at 1:45 PM, hedgomatic <[EMAIL PROTECTED]> wrote: > > I'm trying to reference an element in an each() that's inside an event > function. > > scenario-- > I have a div with a class of .button, several divs with the > class .elementSelected. > I click on the div with the .button class, and then... > > $(".button").click(function() { > elements = new Array(); > $(".elementSelected").each(function() { > var wordsSelected = $(this).html(); // this is > probably wrong. > Array.push(wordsSelected+','); > $alert(elements); //debug > > }); > }); > > > the alert doesn't come up as undefined or null, it just comes up > completely blank. Which is odd because even if $(this) is still > referring to the div that was clicked with the .button class, it has > innerHTML that could be returned. If $(this) does change scope in the > each() loop, then that also has innerHTML that could be returned. > > is this just not possible, or is there a different syntax for > addressing this sort of thing? >