I have a page with two textarea
s and two button
s that copy the content of each textarea
respectively to the user's clipboard when pressed. When the button is pressed and the copying is successful, a tooltip shows saying Copied!
. With how I had it set up before, when 1 button was pressed, then a tooltip was shown for both buttons instead of just the one pressed (see here).
$('button').tooltip({
trigger: 'click',
placement: 'bottom'
});
function setTooltip(message) {
$('button').tooltip('hide')
.attr('data-original-title', message)
.tooltip('show');
}
function hideTooltip() {
setTimeout(function() {
$('button').tooltip('hide');
}, 1000);
}
var clipboard = new Clipboard('button');
clipboard.on('success', function(e) {
e.clearSelection();
setTooltip('Copied!');
hideTooltip();
});
clipboard.on('error', function(e) {
e.clearSelection();
setTooltip('Failed!');
hideTooltip();
});
After basically duplicating the code above I managed to make it so that a tooltip is only shown for the button that is clicked (see here), but this seems like a very beginner-ish way to do it (which I am).