jquery compare last-child to variable

Luey
Luey used Ask the Experts™
on
All of this code works until i get to my if statement.  I am trying to hide a "Next" button when the last element in a div is reached.  It all works except the last part.
Thanks

$("#test").children().css('display', 'none');
    $("#test img:first-child").css('display', 'block');


var currentElement = $("#test img:first-child")
var lastElement = $("#test img:last-child")

function rightNextImage() {
	
	$(currentElement).css('display', 'none').next().css('display', 'block');
	currentElement = currentElement.next(); 
	
	if   (currentElement == lastElement) {
		$("#right_next").hide();
         alert("hello");
         }
   
	 
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
//try

currentElement.is( lastElement )

Author

Commented:
tried it could not make it work
It should work, take a look at this jsfiddle.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial