var $currElement = $("#egy"); $("#gomb").click(function(){ if(!$currElement.next('div').length){ alert("Nincs elem!"); return false; } $currElement = $currElement.next(); $("div").css("background", ""); $currElement.css("background", "blue"); }); $("#reset").click(function () { location.reload(); });