How to Copy and Paste Text in Javascript

How to Copy and Paste Text in Javascript

This is a small tutorial about copying and pasting text in javascript. We are going to use clipboard api to accomplish the job.

This is a small tutorial about copying and pasting text in javascript. We are going to use clipboard api to accomplish the job.

Subscribe: https://www.youtube.com/c/FWAIT/featured

Source Code


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="style.css">
    <title>Document</title>
</head>
<body>

    <div class="container">
        <div>
            <textarea id="copyArea" cols="30" rows="10"></textarea><br>
            <button id="copy">Copy</button>
        </div>

        <div>
            <textarea id="pasteArea" cols="30" rows="10"></textarea><br>
            <button id="paste">Paste</button>
        </div>

    </div>

    <script src="script.js"></script>
</body>
</html>

.container {
  display: flex;
}


document.getElementById('copy').addEventListener('click', ()=>{
    /* document.getElementById('copyArea').select();
    document.execCommand('copy'); */
    let copyArea = document.getElementById('copyArea');
    navigator.clipboard.writeText(copyArea.value);

});

document.getElementById('paste').addEventListener('click', ()=>{
    let pasteArea = document.getElementById('pasteArea');
    pasteArea.value = '';

    navigator.clipboard.readText()
    .then((text)=>{
        pasteArea.value = text;
    });
});

javascript

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Hire Dedicated JavaScript Developers -Hire JavaScript Developers

Hire dedicated JavaScript Developers who are proficient in AngularJS, ReactJS, NodeJS, & VueJS frameworks. Get flexible hiring models as per your business requirements.

What is JavaScript - Stackfindover - Blog

What is PHP: - Who invented PHP, how it works, answers to all such questions about PHP, and much other information, you are going to

JavaScript Shopping Cart - Javascript Project for Beginners

JavaScript Shopping Cart - javascript shopping cart tutorial for beginnersBuy me a coffee 🍺 https://www.paypal.com/paypalme/ziddahSource Code: https://bit....

The essential JavaScript concepts that you should understand

The essential JavaScript concepts that you should understand - For successful developing and to pass a work interview

Learn JavaScript - Full Course for Beginners. DO NOT MISS!!!

In this video tutorial, we'll learn Learn JavaScript - Full Course for Beginners. This complete 134-part JavaScript tutorial for beginners will teach you everything you need to know to get started with the JavaScript programming language. DO NOT MISS!!!