Q:

Only the first if statement is executing in jQuery

I have two jQuery if statements that perform a remove() from a submenu.  They work fine if there is only one true statement, but if there is an id1 & an id2 on the page, only the first if triggers.
if ($('#id1').length==0) { $('#submenu li').eq(2).remove();}

if( $('#id2').length==0) { $('#submenu li').eq(3).remove();}

Updated: Answered below, it was a simple indexing issue where reversing the removal order from the array worked fine.
Thank you.

A:

This is an indexing issue. By removing the 2nd element, the 3rd element now moves into the 2nd position. You then try to remove what used to be the 3rd element, but there's nothing at that index anymore.
To solve this, try removing the elements in reverse order, from highest index to lowest.
if( $('#id2').length==0) { $('#submenu li').eq(3).remove();}

if ($('#id1').length==0) { $('#submenu li').eq(2).remove();}

