jQuery code to copy input value to clipboard

Here we are going to explore jQuery code to copy input value to clipboard,Fortunately we have jQuery library function to copy value to clipboard see the code in details to copy input value to clipboard

 
document.execCommand("copy");

Now see in details jQuery code to copy input value to clipboard

Suppose i have an input field with id result_value

<input type="text" size="12" class="result_input" id="result_value" value="jQuery code to copy input value to clipboard">

I have to copy the the value to clipborad

<script>
(function ( $ ) {
$.fn.copy_text = function() {
$( ".result_value" ).blur(function() {
$("#result_value").select();
document.execCommand("copy");
});
}; 
}( jQuery ));
$('input').copy_text();
</script>

In simple  jQuery code to copy input value to clipboard

$( ".result_value" ).blur(function() {
$("#result_value").select();
document.execCommand("copy");
});

See Demo
copy input value to clipboard

Leave a Reply

Your email address will not be published. Required fields are marked *