Updated contains method to not rely on querySelector