added function to position the cursor at the end of an element