wintercounter / Protip

A new generation jQuery Tooltip plugin
http://protip.rocks
MIT License
359 stars 38 forks source link

How to retrieve title and other data attribute from protip instance? #49

Closed royallife88 closed 2 years ago

royallife88 commented 2 years ago

Hi, How to retrieve title and other data attributes from protip instance on protipshow event.

$('.protip').on('protipshow', function(ItemInstance){
    console.log(ItemInstance.currentTarget.ptTitle, 'title');  //showing undefined
 });
wintercounter commented 2 years ago

I'm from phone now cannot try it, but you can try ItemInstance.data.title in the callback. Please note that this can differ based on how the tooltip was initiated.

royallife88 commented 2 years ago

It did not worked. get error Cannot read properties of undefined (reading 'title')

royallife88 commented 2 years ago
 $.protip({
    defaults: {
      placement: "border",
      animate: false,
      delayIn: 0,
      delayOut: 0,
      interactive: false,
      mixin: "css-no-transition"
    }
  });

Initialized like this.

wintercounter commented 2 years ago

I think the docs need to be updated. The first parameter in the callback is the jQuery event object, the second is the item instance.

$('.protip').on('protipshow', function(ev, ItemInstance){
    console.log(ItemInstance.data.title);
 });

Closing the thread, let me know if you still have problems and I reopen it.

royallife88 commented 2 years ago

Thank you! it's working.