I want to get the class name from a function which has 2 parameters, event and ui.

Example:

$(document).tooltip({ show: null, position: { my: "left top", at: "left bottom" }, open: function( event, ui ) { alert(event.target) ui.tooltip.animate({ top: ui.tooltip.position().top + 10 }, "fast" ); } });

How to get the class name from the given

有帮助吗?

解决方案

the event object has a target attribute (The DOM element that initiated the event).

Hence:

$(event.target) //gives you a jQuery wrapper on the DOM element that initiated the event

In order to get its class, you can do the following:

 $(event.target).attr("class")

I'm not sure what you're trying to accomplish, but I hope this answers your question.

Regarding "ui.item" that you've mentioned - you can do pretty much the same with it too:

$(ui.item).attr("class")

From the few hints you gave me after my questions, I'm guessing you're trying to change the appearance of the tooltip widget, and that's why you're trying to get the "class".

Take a look at jQuery UI Tooltip widget documentation

ui-tooltip: The outer container for the tooltip.
ui-tooltip-content: The content of the tooltip.

EDIT:

If none of these were what you looked for, you can always investigate the event object. take a look at:

event.currentTarget
event.delegateTarget
event.relatedTarget
event.data
event.toElement
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top