Generate an id for the element if one is not set.