Link to home
Start Free TrialLog in
Avatar of Luey
LueyFlag for United States of America

asked on

jquery compare last-child to variable

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

Avatar of Proculopsis
Proculopsis

//try

currentElement.is( lastElement )
Avatar of Luey

ASKER

tried it could not make it work
ASKER CERTIFIED SOLUTION
Avatar of Proculopsis
Proculopsis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial