Copying Text to Clipboard in HTML & JavaScript - Tutorial For Beginners

preview_player
Показать описание
It's relatively straightforward to copy text onto the clipboard with JavaScript, all you need to do is first select the text to copy and then, using JavaScript, copy that selection to the clipboard. It's commonly used on input fields.

In this video I take you through an example of copying text to the clipboard with an input field quite easily and also see how it could work on a regular HTML element.

For your reference, check this out:

Follow me on Twitter @dcode!

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

This is what i have been looking for a long tine

bins.
Автор

This channel is probably the most underrated channel on the youtube

withinbracket
Автор

The simplicity is out of this world! Thank you

GreenBrainX
Автор

This is work only input may be any <div></div>

XodiyevAcademy
Автор

Great one, thanks!
I am trying to copy the result of multiple input fields.

rogeriomartinez
Автор

Nice and helpful, as a lazt tech support I really need a lazy sheet with copy buttons, thank you.

Sd-gerk
Автор

Love this. Thank you! Exactly what I needed. Sub button MASHED. 👍

benjaminschultz
Автор

Extraordinary thank you so much 👌🏼👌🏼👌🏼👌🏼👌🏼

marimuthur
Автор

Thank you for this! Clear and straightforward.

One question: How would I go and predetermine what's IN the box already? So all they'd do is click COPY to grab the text?

keysncoffee
Автор

I've an a tag with my email adress, and i'd like to copy to clipboard my email adress, how do I do it?

postamble
Автор

Great, thanks a lot, it's just what I was looking for

NICK
Автор

The MDN docs say that this is now obsolete. Could you do a quick vid on the alternatives? Cheers

mudandmoss
Автор

Great code!
It is possible to copy only the "text" inputs from the form?
Like in the example bellow:

<form>

<input type"text">

<input type"number">

<input type"text">

</form>

I wanted to be able to 'ignore' the number one and copy just the "text" types, is that possible?

gabrield
Автор

Hey there. How can I copy the text from a <p>text</p>, or <h1>text</h1, or an <span>tex</span>, for exemplo. Could you help me?

pinochio
Автор

i get Uncaught TypeError: myInp.select is not a function
at (code.html:28)
???

User-dkrx
Автор

Can you copy multiple input fields with one copy button?

thelittlecustomgiftco
Автор

You cant paste the text anywhere outside the html document itself. What is the point of this code if all i get back is a function

=> {
console.log(detailsText)
})

justinjenecke
Автор

if you turn on captions...he says "hey guys hows it going? my name is dumb"
RIP...

maskboy
Автор

next time, it would be extremely helpful to include the code in the description.

ttvjackriot
Автор

good and this code can also be use to copy

shahzaib
join shbcf.ru