How to copy text in javascript | javascript tutorial | HTML | javaScript

Published: 04 December 2021
on channel: CODEHUNT • 243k views
46
1

How to copy text in javascript | javascript tutorial | HTML | javaScript


In this video i have explained that how can you copy any text or any input text to clipboard with javascript.

code:-

function copy(){
let text = document.getElementById("text");
let mainTxt = text.innerText;
// console.log(mainTxt);
let inputElm = document.createElement('input');
inputElm.setAttribute('value', mainTxt);
document.body.appendChild(inputElm);

// To select data
inputElm.select();

// To copy data
document.execCommand('copy');

// Now we have to remove this input
inputElm.parentNode.removeChild(inputElm);

// so it's working now
}


Keyword for placement:-
copy to clipboard javascript react,
copy to clipboard javascript codepen,
copy to clipboard javascript not working,
copy to clipboard javascript mobile,
copy to clipboard javascript variable,
copy to clipboard javascript onclick,
copy to clipboard javascript not working in safari,
copy to clipboard javascript code,
copy to clipboard javascript android,
copy to clipboard javascript button,
copy to clipboard javascript ios,
copy to clipboard reactjs,
copy to clipboard javascript safari,
copy to clipboard javascript vue,
copy to clipboard javascript 2021


On this page of the site you can watch the video online How to copy text in javascript | javascript tutorial | HTML | javaScript with a duration of hours minute second in good quality, which was uploaded by the user CODEHUNT • 243k views 04 December 2021, share the link with friends and acquaintances, this video has already been watched 46 times on youtube and it was liked by 1 viewers. Enjoy your viewing!