UNPKG

743 BHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <title>function-target</title>
6 <meta name="viewport" content="width=device-width, initial-scale=1">
7</head>
8<body>
9 <!-- 1. Define some markup -->
10 <button class="btn">Copy</button>
11 <div>hello</div>
12
13 <!-- 2. Include library -->
14 <script src="../dist/clipboard.min.js"></script>
15
16 <!-- 3. Instantiate clipboard -->
17 <script>
18 var clipboard = new ClipboardJS('.btn', {
19 target: function() {
20 return document.querySelector('div');
21 }
22 });
23
24 clipboard.on('success', function(e) {
25 console.log(e);
26 });
27
28 clipboard.on('error', function(e) {
29 console.log(e);
30 });
31 </script>
32</body>
33</html>