4
I am trying to make the Clipboard.js change the copy button from "COPY" to "COPIED" after clicking without losing the function it has that selects the target code.
Would anyone know how to do?
! function() {
for (var a = document.getElementsByTagName("pre"), b = document.getElementById("paste-content"), c = 0; c < a.length; c++) {
var d = a[c].children[0].className.indexOf("language-");
if (0 === d) {
var e = document.createElement("button");
e.className = "copy-button", e.textContent = "COPY", a[c].appendChild(e)
}
}
var f = new Clipboard(".copy-button", {
target: function(a) {
return a.previousElementSibling
}
})
}();
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js"></script>
<pre class="input button border"><code class="language-less" id="dialog_coupon_code_1">CODE 1</code></pre>
<pre class="input button border"><code class="language-less" id="dialog_coupon_code_2">CODE 2</code></pre>
<pre class="input button border"><code class="language-less" id="dialog_coupon_code_3">CODE 3</code></pre>
Excellent, you could also implement error if any error occurs due to some browser configuration, yet yes +1 as it is already a great answer.
– Guilherme Nascimento
Perfect, it was just that. Thank you!
– Mr.Cranium