getAttributeOnSelection function

Needs docs etc.  Not been tested neither, living life on the edge.