use selected element instead of document

This is a fix for: https://rally1.rallydev.com/#/11744709050d/detail/defect/13437548149