I\'m using clipboard.js to copy some text from a textarea
, and that\'s working fine, but I want to show a tooltip saying \"Copied!\" if it was successfully copi
This solution work, if you have some buttons and etc:
function setTooltip(e,message) {
$(e.trigger).tooltip({
trigger: 'click',
placement: 'bottom'
});
$(e.trigger).tooltip('hide')
.attr('data-original-title', message)
.tooltip('show');
}
function hideTooltip(e) {
setTimeout(function() {
$(e.trigger).tooltip('hide');
}, 1000);
}
// Clipboard
var clipboard = new Clipboard('button');
clipboard.on('success', function(e) {
setTooltip(e,'Copied!');
hideTooltip(e);
});
clipboard.on('error', function(e) {
setTooltip(e,'Failed!');
hideTooltip(e);
});