3

I'm using clipboard plugin HERE

I would like to modify the bootstrap 3 tooltip title on clipboard success event but I've an error "TypeError: e.trigger.tooltip is not a function"

<div class="panel panel-default">
  <div class="panel-body">
    <p>
      USERNAME : <a href="#" title="Copy" class="btn-copy" data-clipboard-text="foo">foo</a>
      <br />
      PASSWORD : <a href="#" title="Copy" class="btn-copy" data-clipboard-text="bar">bar</a>
    </p>
  </div>
</div>

JS

$(".btn-copy").tooltip({
  placement: 'right'
});

clipboard.on('success', function(e) {
  e.clearSelection();
  console.log(e.trigger); -->//<a class="btn-copy" data-clipboard-text="foo" title="" href="#" data-original-title="Copy" aria-describedby="tooltip870310">

  e.trigger.tooltip({ title: 'Copied' });
});

clipboard.on('error', function(e) {
  console.log(e);
});

JSFIDDLE

How can solve this? Thanks

Paolo Rossi
  • 2,490
  • 9
  • 43
  • 70

1 Answers1

5

First of all e.trigger is a DOM element not a jQuery element. So you need to wrap it like this $(e.trigger) Here is the working code from there https://stackoverflow.com/a/30803562/5119765 :

$(e.trigger).attr('title', 'Copied').tooltip('fixTitle').tooltip('show');
Community
  • 1
  • 1
ADreNaLiNe-DJ
  • 4,787
  • 3
  • 26
  • 35