I am trying to get the reference of the hovered element in my tooltip. I managed to get it like this but I feel there is better way to do this...any ideas?

Here is my jsfiddle

$(function () {

  var i = 0;
  $(document).on("tooltipopen", function (event, ui) {


      var $el = $.data(this, 'ui-tooltip').
      tooltips["ui-tooltip-" + i];//There needs t be a better way...

      console.log($el.text() + " index : " + i);

      i++;
  });
有帮助吗?

解决方案

That would be event.toElement

$(document).on("tooltipopen", function (event, ui) {
    console.log( $(event.toElement).text() );
});

FIDDLE

其他提示

I would do it like this

open: function(e){
    console.log(e.originalEvent.target);
}

http://jsfiddle.net/RyfDb/3/

Since it's a DOM element, you might want to pass it to the jQuery function to get access to the jQuery methods:

$(e.originalEvent.target);

http://api.jqueryui.com/tooltip/#event-open

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top