Skip to content

Instantly share code, notes, and snippets.

@kingjmaningo
Last active June 12, 2021 03:11
Show Gist options
  • Save kingjmaningo/53f232518c5a32d7b0132b92a43505f4 to your computer and use it in GitHub Desktop.
Save kingjmaningo/53f232518c5a32d7b0132b92a43505f4 to your computer and use it in GitHub Desktop.
Copy text from an input field
<div class="input-group mb-3">
<input type="text" class="form-control text-value" value="sample text here">
<div class="input-group-append">
<button class="btn btn-outline-secondary copy-url" type="button"><i class="fas fa-copy"></i></button>
</div>
</div>
<script>
jQuery(document).ready(function($){
$('.copy-url').click(function() {
var url = jQuery(this).parent().parent().find('.text-value').val();
var copyHex = document.createElement('input');
copyHex.value = url
document.body.appendChild(copyHex);
copyHex.select();
document.execCommand('copy');
copyHex.remove();
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment