Elementals.js

Latest Version: 3.7 Final 20 December 2018

Method _.Node.addCopyButton

Summary:

Adds a button to the page that when clicked selects the contents of the associated DOM element as if you had done so by clicking and dragging the mouse. The selection is then copied to the clipboard in a cross browser compatible manner.

  • In legacy IE this may trigger a warning dialogue asking permission.
  • In some browsers this functionality may be disabled/unavailable
  • No fallbacks to systems like Adobe Flash are provided for unsupported browsers.
Calling Convention:
_.Node.addCopyButton(Element[, text[, node[, place]]])
Parameters:
Element
The target Element that will be selected when the new button is clicked.
text optional
The text to be placed inside the button. If omitted, 'select' will be used.
Node optional
The element the new button is to be added to the DOM relative to. If omitted, Element.parentNode will be used.
place optional

Where the element will be placed. If place is omitted or invalid, 'before' is used. See DOM-JON Placement for more information.

Returns:
Nothing

Example #1

HTML

<div id="test">Test</h1>

JavaScript

_.Node.addCopyButton(_d.getElementById('test'));

Inserts a <button>select</button> before div#test that when clicked selects the contents of that element and attempts to copy it to the clipboard.


A live example of this method can be found in our demonstrations section.