copy innerHLM of div using clipboardjs

Hi everybody,
I need to copy the content of the div to the desktop when clicked the div using

<div id="id1" onclick="copy_content_to_clipboard(this);">

Anybody can help me?
Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
here we go - no need to do the onclick handler:
<!DOCTYPE html>

    <link rel="stylesheet" href="style.css">
    <script src=""></script>

    <!-- 1. Define some markup -->
    <div id="myCopySource" style="border: 2px solid" data-clipboard-action="copy" data-clipboard-target="#myCopySource"><h1>Inner Heading</h1><br/><span>And a span is also in here.</span></div>
    <!-- 2. Instantiate clipboard -->
    var clipboard = new Clipboard("#myCopySource");
    clipboard.on('success', function(e) {
    clipboard.on('error', function(e) {


Open in new window

Live sample:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
myyisAuthor Commented:
Thank you very much for your quick answer. I have 2 questions:

1. How is it working for  "onclick" without an onclick script, if I want to make it onmouseover, what shall I do?

2.  At the examples here when you click the copy button you see a small confirmation pop-up. How can turn this on?
Rainer JeschorCommented:
1: thats because the constructor implements the onclick listener.
For an onmouseover you might track that event and fire a click event on the same element. But not sure if this makes sense (from an user perspective).

2: Because they implemented additionally a showTooltip function
showTooltip(e.trigger, 'Copied!');

Open in new window

but only on buttons with the class "btn".

myyisAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.