Title: Copy to clipboard on hover
Tags: javascript;dom-events;copy-paste
Question: I am trying to copy text to clipboard on hover and noticed that it only works on click (document.body.addEventListener('click', copy, true);), but when you try to trigger copy on hover it doesn't work (document.body.addEventListener('mouseover', copy, true);). I was playing around with this  example and was wondering why that is the case.

Here is the accepted answer: document.execCommand needs a user event to work. It will not work on hover, but it will on clicks and the like (mousedown, mouseup, etc.).
You still might want to check compatibility (here). Refer to this original answer and (this) jsFiddle. It seems browsers do support it consistently now, but you still need to make sure you want to target those versions in the table.
$('.big').hover(function () {
// will not work, no user action
$('input').select();
document.execCommand('copy');
$('.big').mousedown(function () {
//works
document.execCommand('copy');
Copy commands triggered from document.execCommand() will only affect the contents of the real clipboard if the event is dispatched from an event that is trusted and triggered by the user, or if the implementation is configured to allow this. How implementations can be configured to allow write access to the clipboard is outside the scope of this specification.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:09/08/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><dom-events><copy-paste>', 'Title': 'Copy to clipboard on hover', 'ViewCount': 4098, 'id': 39389776, 'user_AboutMe': '', 'user_AccountId': 2639289.0, 'user_DisplayName': 'ramesh', 'user_Reputation': 1986.0, 'user_Views': 128.0, 'user_id': 2283302.0}}