[jQuery] $(this) scope (each() nested in an event)
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?