1

Let me start with that i'm a beginner on javascript and I just about understand a click toggle. I am making a site like flatuicolors.com and it that when you click on a div, it will copy the colour. I have wrote each colour in the each div in a P tag and was wondering if you can click to copy the P tag in that div.

<div class="main-colour-container col-group-1">
    <div class="colours-featured" id="div2">

        <div class="colour-box" style="background:#F22613;">
            <div class="inside-colour-box">
                <div class="colour-box-text fade">
                    <p>#F22613</p>
                </div>
            </div>
        </div>

        <div class="colour-box" style="background:#F44336;">
            <div class="inside-colour-box">
                <div class="colour-box-text fade">
                    <p>#F44336</p>
                </div>
            </div>
        </div>
        <div class="colour-box" style="background:#C62828;">
            <div class="inside-colour-box">
                <div class="colour-box-text fade">
                    <p>#C62828</p>
                </div>
            </div>
        </div>
        <div class="colour-box" style="background:#DB3D45;">
            <div class="inside-colour-box">
                <div class="colour-box-text fade">
                    <p>#DB3D45</p>
                </div>
            </div>
        </div>
    </div>
</div>
leham789
  • 117
  • 2
  • 12
  • 2
    Possible duplicate of [How do I copy to the clipboard in JavaScript?](http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) – 4castle Aug 18 '16 at 14:24
  • It already answered here (http://stackoverflow.com/a/22581382/4804765) – Drkdra Aug 18 '16 at 14:25
  • Yes, it may have been asked before but I do not understand still from that thread as I am a beginner at javascript – leham789 Aug 18 '16 at 14:27
  • Please be specific then with what you don't understand about it, so we know how to help. – 4castle Aug 18 '16 at 14:27

1 Answers1

5

Coincidentally I ahd made the exact same PEN once.

Here is the link. Hope it helps. :)

function copyToClipboard(element) {
  var $temp = $("<input>");
  $("body").append($temp);
  $temp.val($(element).text()).select();
  document.execCommand("copy");
  $temp.remove();
}

Tick the Answer if it helped.

theLearner
  • 363
  • 4
  • 16