JSFiddle - React, Tailwind, and code Playground
HTML
<div class="ipDiv tk-saffran">
<div class="ipText">
<h2 id="ip">play.MineGlade.net</h2>
</div>
<div class="copyButton">
<button onclick="copyIp()">Copy IP</button>
<script>
function copyIp() {
$("#ip").selectText();
document.execCommand("Copy");
}
</script>
</div>
</div>
JavaScript
jQuery.fn.selectText = function(){
var doc = document;
var element = this[0];
console.log(this, element);
if (doc.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
};