All those parent() calls look very fragile. Maybe use .closest('nav[class="sequence-bottom"]') (or whatever it may be) and check whether that's non-empty.