0

When a tippy.js tooltip is triggered, I want to be able to get "this" from it.
I've tried:

tippy(".sampleID",{
    arrow:true,
    placement: "bottom",
  content(reference) {                            
    const title = reference.getAttribute('title'); 
    var tid=$(this).attr("id"); // is undefined
    return title;
  }
});

How do I get "this" for class .sampleID that was hovered on?

JSFiddle

Shawn
  • 3,031
  • 4
  • 26
  • 53

1 Answers1

3

You can just use the reference provided as the argument, which refers to the current element matching .sampleID.

In your case I think you're trying to access the parent element though, which contains your id.

  tippy(".sampleID",{
    arrow:true,
    placement: "bottom",
    content(reference) {                              
      const title = reference.getAttribute('title');
      const tid = reference.parentElement.getAttribute('data-id');
      // jQuery: const tid = $(reference).parent().data('id');
      return title+"<br>"+tid;
    }
  });
Grabofus
  • 1,924
  • 14
  • 17