I'm an amateur in JavaScript and jQuery (im a java programmer)and I'm wondering what is truly going on in the background of this comparison:
if (current == $("#hero div:last") )
I thought it would return true if they are the same object, just as would happen in Java since it would just be the same address in memory(there is only one item in the html with a class of current), but the code is not working and the condition is never met. Then I thought since multiple objects going to one var make it an Array, maybe by "current var is actually an array of size 1 so i changed it to:
if (current[0] == $("#hero div:last") )
But this did not work either. Could someone please explain what is actually going on or if i am missing the point completely? Here is the rest of the code just in case:
$("document").ready(function(){
setInterval("rotate()",500);
});
function rotate() {
var current = $("#hero div.current");
if (current == $("#hero div:last") ){
var next = $("#hero div:first");
}else {
var next = current.next();
}
current.removeClass("current").addClass("previous");
next.addClass("current");
}