I am using a bit of jquery and javascript mashed up in this weird hodgepodge of code.
var SELECTED_ELEMENT; //this ends up being a JS array of ELEMENTS like the following line.
SELECTED_ELEMENT.push($(this).closest(".draggable"));
//Now i wanted to select stuff
$(".draggable").click(function(){
var found = 0;
for (var i = 0; i < SELECTED_ELEMENT.length; i++){
if(SELECTED_ELEMENT[i] == this){
found = 1;
}
}
if(found == 1){
alert("yep");
}else{
alert("nope");
}
});
//this doesnt seem to do what i want.
The question at hand is that this is never returning true, even when it is. I was just trying to find a way to in javascript search the array for it. You would think that a simple search through the array would figure it out, but possibly an improper reference to ‘this’
There are some issues, like
int found = 0which isn’t even javascript. Then you are pushing jQuery objects to an array, and comparing them to dom elements.Push the elements instead:
demo: http://jsfiddle.net/sqj42/