The focus and selection events give us detailed information about what actions the user is taking in the document.
Focus events occur on elements such as BUTTON and various types of INPUT objects that can receive the input focus. An element receives the input focus when the user clicks it with the mouse or navigates to it using the keyboard.
These events are useful for knowing when to prepare an element to receive input from the user.
For these elements, the onfocus event fires when an element receives the focus, and the onblur event fires when an element loses the focus.
Note that the focus events fire whether moving the input focus between elements in the document or between frames in the window or even applications on the desktop.
For example, if a control in the document has the focus and the user switches to another application, the onblur event fires for that control. When the user switches back to the document, the onfocus event fires. It is not possible to cancel the loss of focus.
Selection events occur when the user selects a portion of the document by using the mouse or keyboard.
The onselectstart event fires when a selection is first initiated. Such events fire, for example, when the user clicks a character or object in the document.
The default action for the onselectstart event is to move the selection to the given character or object and highlight that selection. We can cancel this default action by returning false.
The onselect event fires when the user changes the selection, for example, by moving the mouse over a portion of the document while holding down the mouse button.
The ondragstart event fires when the user first begins to drag the selection. The user can drag a selection by holding down the mouse button on the current selection and moving the mouse.
The default action for this event is to prepare the selection to be copied to another element. We can cancel this default action by returning false.