Get a free trial // Grow your CSS skills // Land your dream job

Click div & copy code to pasteboard?

  • # January 6, 2013 at 4:23 pm

    Howdy All,

    Curious if anyone can suggest a method, using jQuery perhaps, to click a div and have the related code copied to the pasteboard. Or something similar.

    Thank You

    # January 6, 2013 at 4:54 pm

    I used ZeroClipboard (flash) because it’s the only way to avoid a Javascript popup alert.

    This is what uses along with majority of other sites.

    # January 6, 2013 at 6:44 pm

    chris is correct. due to security issues javascript doesnt have direct access to the OS clipboard.

    in the past i’ve used this plugin:

    note that it also requires flash, but is really easy to implement.

    # January 7, 2013 at 3:44 pm

    Thank you – will have a further read

    # January 7, 2013 at 3:48 pm

    @NSR Click the titles and you will see it in action

    # January 7, 2013 at 4:54 pm

    Any way to do this in IOS?

    # January 7, 2013 at 5:10 pm

    Not with flash. It does not work on some Android tablets either.

    # January 7, 2013 at 7:06 pm

    Yeah I googled the other day for awhile looking for a non flash way.

    # January 7, 2013 at 7:09 pm

    There is a way with jQuery/Javascript but the user receives a popup alert (stated above).

    Your best bet is to detect if flash is supported (somehow), if not, remove the flash button. The user can tap (click) on the input and copy it the hard way.

    # January 8, 2013 at 4:00 pm

    Interesting Thanks for all the feedback

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed