Posted in

Copiar texto al portapapeles con jQuery

Para copiar un texto al portapapeles (clipboard) mediante jQuery podemos usar la siguiente función.

 $('.copy-concept').click(function(){
            var $temp = $("<input>");
            $("body").append($temp);
            $temp.val($.trim($(this).prev().text())).select();
            document.execCommand("copy");
            $temp.remove();
        });

Eliminando previamente los saltos de línea o las tabulaciones del texto:

 $('.copy-concept').click(function(){
            var $temp = $("<input>");
            $("body").append($temp);
            $temp.val($(this).prev().text()).select();
            document.execCommand("copy");
            $temp.remove();
        });

Deixa un comentari

L'adreça electrònica no es publicarà. Els camps necessaris estan marcats amb *


The reCAPTCHA verification period has expired. Please reload the page.