Clipboard.js: Copy text from Hidden Input

Created on 21 Sep 2016  路  3Comments  路  Source: zenorocha/clipboard.js

It is possible to get the value of input type hidden ?

The input :
<input type='hidden' value='mysekretvalue' id='hidden-0' />

The link :
<a href='#' class='link-copy' title='copy to clipboard' data-clipboard-target='#hidden-0'>

Most helpful comment

Solution:

var inputhidden = $(this).next();
new Clipboard('.link-copy', {
    text: function (trigger) {
          return inputhidden.val();
     }
});

All 3 comments

Solution:

var inputhidden = $(this).next();
new Clipboard('.link-copy', {
    text: function (trigger) {
          return inputhidden.val();
     }
});

This feels like a common use case, would it be worth adding a note about it in the readme?

It was a little strange debugging this using the vanilla setup, the success event fires but the clipboard hasn't changed.

I'm having trouble copying the contents of any input field that's hidden using CSS.

Was this page helpful?
0 / 5 - 0 ratings