Utility function for getting an element's id and creating a unique one if not present