Add a function to check if parent-exists and use that to build the selector