Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

copy-to-clipboard-id

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copy-to-clipboard-id

Simple copy function to clipboard

  • 0.0.10
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

npm stat npm version install size

Copy To Clipboard ID

Simple copy function to clipboard

Installation

npm i copy-to-clipboard-id

or

yarn add copy-to-clipboard-id

With CDN

<script src="https://cdn.jsdelivr.net/npm/copy-to-clipboard-id@0.0.9"></script>
VanilaJS
var copyClipboard = require("copy-to-clipboard-id");

function copy() {
    copyClipboard({ text: "Copy data" });
}
ReactJS
import React from "react";
import copyClipboard from "copy-to-clipboard-id";

export default function App() {
    return (
        <>
            <button onClick={() => copyClipboard({ text: "Copy data" })}>
                Click Copy
            </button>
            <br />
            <input type="text" id="text" value="Copy from value input" />
            <button onClick={() => copyClipboard({ id: "text" })}>
                Click Copy Input
            </button>
            <br />
            <p id="html">copy from html tag</p>
            <button onClick={() => copyClipboard({ id: "html" })}>
                Click Copy Text Html Tag
            </button>
            <button
                onClick={() =>
                    copyClipboard({
                        id: "html",
                        onCopy: (text) => {
                            console.log(text);
                        },
                    })
                }
            >
                Click Copy Text Html Tag With Callback
            </button>
        </>
    );
}
VueJS
<script setup lang="ts">
import copyClipboard from "copy-to-clipboard-id";

function cb(text: string) {
  console.log(text);
}
</script>

<template>
  <button @click="() => copyClipboard({ text: 'Copy data' })">
    Click Copy
  </button>
  <br />
  <input type="text" id="text" value="Copy from value input" />
  <button @click="() => copyClipboard({ id: 'text' })">Click Copy Input</button>
  <br />
  <p id="html">copy from html tag</p>
  <button @click="() => copyClipboard({ id: 'html' })">
    Click Copy Text Html Tag
  </button>
  <button
    @click="
      () =>
        copyClipboard({
          id: 'html',
          onCopy: cb,
        })
    "
  >
    Click Copy Text Html Tag With Callback
  </button>
</template>

API

NoValueDescription
1textThe text to be copied
2idthe id of the html tag element that will be fetched for copying but if you already use text this will not work
3onCopycallback function

TypeScript

Add in file index.d.ts or global.d.ts

declare module 'copy-to-clipboard-id';

Browser compatibility

Browser compatibility

Live Demo React

Live Demo With Editor

Live Demo

Keywords

FAQs

Package last updated on 03 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc