zeroclipboard - copying and formatting text

1k Views Asked by At

I am struggling to create a selection set to pass through to a zeroclipboard client to copy the contents of the various HTML elemnts in a basically formatted form. I can pass through text to the client directly from the variable var myTextToCopy = "Hi, this is the text to copy!"; but cannot get the text content of HTML elements to work.

Can someone point out where I am going wrong?

<script src="_assets/js/ZeroClipboard.js" type="text/javascript"></script> 
      <script language="JavaScript">
                var clip = new ZeroClipboard.Client();
    var myTextToCopy = $(".sideInfo ul:first-child").text() + "\r\n" + $(".sideInfo ul:nth-child(2)").text() + "\r\n" + $(".sideInfo ul:nth-child(3)").text() + $('.description').text();
                clip.setText( myTextToCopy );
                clip.glue( 'copyme' );
        </script>


<div id="copyme">Copy To Clipboard</div>

    <div class="sideInfo">    
      <ul>
        <li>Episode: x</li>
        <li>Production house: x</li>
        <li>Contacts: Tim nicebutdim<br><a href="mailto:[email protected]">[email protected]</a></li>
      </ul>
    </div>

  <div class="description">
Text text texttext <br /> text text text</div>
1

There are 1 best solutions below

4
On

Instead of

clip.setText( txt );

use

clip.setText( myTextToCopy );

Then try to use

clip.setText($(".sideInfo").text());

Finally add this around your code

$(document).ready(function() {

// your code

)};