suppose I have an :
You need to check the length property.
if ($("li.test").next().length) { //has next } else { //last elem }
Keep in mind that jQuery usually returns itself so you can chain. Getting the length property of that object will give you the information
length