Tighten code for checking if any ancestor matches selector