User Interaction
To specify when the Tooltip should be shown and hidden, set the showEvent and hideEvent properties. These properties can accept several events at once as well as an object.
jQuery
$(function() { $("#tooltipContainer").dxTooltip({ target: "#image", showEvent: 'dxhoverstart', hideEvent: 'dxhoverend', contentTemplate: function (contentElement) { contentElement.append( $("<p />").text("Tooltip content") ) } }); });
<img id="image" src="https://url/to/an/image" /> <div id="tooltipContainer"></div>
Angular
<img id="image" src="https://url/to/an/image" /> <dx-tooltip target="#image" showEvent="dxhoverstart" hideEvent="dxhoverend"> <div *dxTemplate="let data of 'content'"> <p>Tooltip content</p> </div> </dx-tooltip>
import { DxTooltipModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxTooltipModule ], // ... })
Vue
<template> <div> <img id="image" src="https://url/to/an/image" /> <DxTooltip target="#image" show-event="dxhoverstart" hide-event="dxhoverend"> <template> <p>Tooltip content</p> </template> </DxTooltip> </div> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxTooltip } from 'devextreme-vue/tooltip'; export default { components: { DxTooltip } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { Tooltip } from 'devextreme-react/tooltip'; const renderContent = () => { return ( <p>Tooltip content</p> ); } class App extends React.Component { render() { return ( <div> <img id="image" src="https://url/to/an/image" /> <Tooltip target="#image" showEvent="dxhoverstart" hideEvent="dxhoverend" contentRender={renderContent} /> </div> ); } } export default App;
ASP.NET MVC Controls
@(Html.DevExtreme().Tooltip() .Target("#image") .ShowEvent("dxhoverstart") .HideEvent("dxhoverend") .ContentTemplate(@<text> <p>Tooltip content</p> </text>) ) <img id="image" src="https://url/to/an/image" />
The Tooltip can also be hidden when a user clicks outside it. To control this behavior of the Tooltip, use the hideOnOutsideClick property.
jQuery
$(function() { $("#tooltipContainer").dxTooltip({ target: "#image", showEvent: 'dxhoverstart', hideEvent: 'dxhoverend', hideOnOutsideClick: false, contentTemplate: function (contentElement) { contentElement.append( $("<p />").text("Tooltip content") ) } }); });
<img id="image" src="https://url/to/an/image" /> <div id="tooltipContainer"></div>
Angular
<img id="image" src="https://url/to/an/image" /> <dx-tooltip target="#image" showEvent="dxhoverstart" hideEvent="dxhoverend" [hideOnOutsideClick]="false"> <div *dxTemplate="let data of 'content'"> <p>Tooltip content</p> </div> </dx-tooltip>
import { DxTooltipModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxTooltipModule ], // ... })
Vue
<template> <div> <img id="image" src="https://url/to/an/image" /> <DxTooltip target="#image" show-event="dxhoverstart" hide-event="dxhoverend" :hide-on-outside-click="false"> <template> <p>Tooltip content</p> </template> </DxTooltip> </div> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxTooltip } from 'devextreme-vue/tooltip'; export default { components: { DxTooltip } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { Tooltip } from 'devextreme-react/tooltip'; const renderContent = () => { return ( <p>Tooltip content</p> ); } class App extends React.Component { render() { return ( <div> <img id="image" src="https://url/to/an/image" /> <Tooltip target="#image" showEvent="dxhoverstart" hideEvent="dxhoverend" contentRender={renderContent} hideOnOutsideClick={false} /> </div> ); } } export default App;
ASP.NET MVC Controls
@(Html.DevExtreme().Tooltip() .Target("#image") .ShowEvent("dxhoverstart") .HideEvent("dxhoverend") .ContentTemplate(@<text> <p>Tooltip content</p> </text>) .HideOnOutsideClick(false) ) <img id="image" src="https://url/to/an/image" />
API
jQuery
To show or hide the Tooltip programmatically, call the show() or hide() method. The same thing can be done using the toggle(showing) method. Pass true or false to this method to show or hide the Tooltip, respectively.
$(function() { $("#tooltipContainer").dxTooltip({ target: "#image", contentTemplate: function (contentElement) { contentElement.append( $("<p />").text("Tooltip content") ) } }); $("#showButton").dxButton({ text: "Show the Tooltip", onClick: function () { $("#tooltipContainer").dxTooltip("show"); // === or === $("#tooltipContainer").dxTooltip("toggle", true); } }); $("#hideButton").dxButton({ text: "Hide the Tooltip", onClick: function () { $("#tooltipContainer").dxTooltip("hide"); // === or === $("#tooltipContainer").dxTooltip("toggle", false); } }); });
<img id="image" src="https://url/to/an/image" /> <div id="tooltipContainer"></div> <div id="showButton"></div> <div id="hideButton"></div>
ASP.NET MVC Controls
To show or hide the Tooltip programmatically, call the show() or hide() method. The same thing can be done using the toggle(showing) method. Pass true or false to this method to show or hide the Tooltip, respectively.
@(Html.DevExtreme().Tooltip() .ID("tooltip") .Target("#image") .ContentTemplate(@<text> <p>Tooltip content</p> </text>) ) <img id="image" src="https://url/to/an/image" /> @(Html.DevExtreme().Button() .ID("showButton") .Text("Show the Tooltip") .OnClick("showTooltip") ) @(Html.DevExtreme().Button() .ID("hideButton") .Text("Hide the Tooltip") .OnClick("hideTooltip") ) <script type="text/javascript"> function showTooltip () { $("#tooltip").dxTooltip("show"); // ===== or ===== $("#tooltip").dxTooltip("toggle", true); } function hideTooltip () { $("#tooltip").dxTooltip("hide"); // ===== or ===== $("#tooltip").dxTooltip("toggle", false); } </script>
jQuery
The show() method called without arguments shows the Tooltip for the target specified beforehand. If you need to change the target once, call the show(target) method.
$(function() { // ... $("#showButton").dxButton({ text: "Show the Tooltip", onClick: function () { $("#tooltipContainer").dxTooltip("show", "#newTarget"); } }); });
ASP.NET MVC Controls
The show() method called without arguments shows the Tooltip for the target specified beforehand. If you need to change the target once, call the show(target) method.
// ... <script type="text/javascript"> function showTooltip () { $("#tooltip").dxTooltip("show", "#newTarget"); } // ... </script>
Angular
To show or hide the Tooltip programmatically, bind the visible property of the Tooltip to a component property. After that, change this component property, and the Tooltip will appear or disappear.
<img id="image" src="https://url/to/an/image" /> <dx-tooltip target="#image" [visible]="isTooltipVisible"> <div *dxTemplate="let data of 'content'"> <p>Tooltip content</p> </div> </dx-tooltip> <dx-button text="Show the Tooltip" (onClick)="isTooltipVisible = true"> </dx-button> <dx-button text="Hide the Tooltip" (onClick)="isTooltipVisible = false"> </dx-button>
import { DxTooltipModule, DxButtonModule } from "devextreme-angular"; // ... export class AppComponent { isTooltipVisible: boolean = false; } @NgModule({ imports: [ // ... DxTooltipModule ], // ... })
Vue
To show or hide the Tooltip programmatically, bind the visible property of the Tooltip to a component property. After that, change this component property, and the Tooltip will appear or disappear.
<template> <div> <img id="image" src="https://url/to/an/image" /> <DxTooltip target="#image" v-model:visible="isTooltipVisible"> <template> <p>Tooltip content</p> </template> </DxTooltip> <DxButton text="Show the Tooltip" @click="showTooltip" /> <DxButton text="Hide the Tooltip" @click="hideTooltip" /> </div> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxTooltip } from 'devextreme-vue/tooltip'; import { DxButton } from 'devextreme-vue/button'; export default { components: { DxTooltip, DxButton }, data() { return { isTooltipVisible: false } }, methods: { showTooltip() { this.isTooltipVisible = true; }, hideTooltip() { this.isTooltipVisible = false; } } } </script>
React
To show or hide the Tooltip programmatically, bind the visible property of the Tooltip to a state property. After that, change this state property, and the Tooltip will appear or disappear.
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { Tooltip } from 'devextreme-react/tooltip'; import { Button } from 'devextreme-react/button'; const renderContent = () => { return ( <p>Tooltip content</p> ); } class App extends React.Component { constructor(props) { super(props); this.state = { isTooltipVisible: false }; this.showTooltip = this.showTooltip.bind(this); this.hideTooltip = this.hideTooltip.bind(this); } showTooltip() { this.setState({ isTooltipVisible: true }); } hideTooltip() { this.setState({ isTooltipVisible: false }); } render() { return ( <div> <img id="image" src="https://url/to/an/image" /> <Tooltip target="#image" visible={this.state.isTooltipVisible} contentRender={renderContent} onHiding={this.hideTooltip} /> <Button text="Show the Tooltip" onClick={this.showTooltip} /> <Button text="Hide the Tooltip" onClick={this.hideTooltip} /> </div> ); } } export default App;
Events
To execute certain commands before or after the Tooltip was shown/hidden, handle the showing, shown, hiding or hidden event. If the event handling function is not going to be changed during the lifetime of the UI component, assign it to the corresponding onEventName property when you configure the UI component.
jQuery
$(function () { $("#tooltipContainer").dxTooltip({ // ... onShowing: function (e) { // Handler of the "showing" event }, onShown: function (e) { // Handler of the "shown" event }, onHiding: function (e) { // Handler of the "hiding" event }, onHidden: function (e) { // Handler of the "hidden" event } }); });
Angular
<dx-tooltip ... (onShowing)="onShowing($event)" (onShown)="onShown($event)" (onHiding)="onHiding($event)" (onHidden)="onHidden($event)"> </dx-tooltip>
import { DxTooltipModule } from "devextreme-angular"; // ... export class AppComponent { onShowing (e) { // Handler of the "showing" event }, onShown (e) { // Handler of the "shown" event }, onHiding (e) { // Handler of the "hiding" event }, onHidden (e) { // Handler of the "hidden" event } } @NgModule({ imports: [ // ... DxTooltipModule ], // ... })
Vue
<template> <DxTooltip ... @showing="onShowing" @shown="onShown" @hiding="onHiding" @hidden="onHidden" /> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxTooltip } from 'devextreme-vue/tooltip'; export default { components: { DxTooltip }, methods: { onShowing(e) { // Handler of the 'showing' event }, onShown(e) { // Handler of the 'shown' event }, onHiding(e) { // Handler of the 'hiding' event }, onHidden(e) { // Handler of the 'hidden' event } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { Tooltip } from 'devextreme-react/tooltip'; class App extends React.Component { onShowing(e) { // Handler of the 'showing' event } onShown(e) { // Handler of the 'shown' event } onHiding(e) { // Handler of the 'hiding' event } onHidden(e) { // Handler of the 'hidden' event } render() { return ( <Tooltip ... onShowing={this.onShowing} onShown={this.onShown} onHiding={this.onHiding} onHidden={this.onHidden} /> ); } } export default App;
ASP.NET MVC Controls
@(Html.DevExtreme().Tooltip() // ... .OnShowing("tooltip_onShowing") .OnShown("tooltip_onShown") .OnHiding("tooltip_onHiding") .OnHidden("tooltip_onHidden") ) <script type="text/javascript"> function tooltip_onShowing (e) { // Handler of the "showing" event }, function tooltip_onShown (e) { // Handler of the "shown" event }, function tooltip_onHiding (e) { // Handler of the "hiding" event }, function tooltip_onHidden (e) { // Handler of the "hidden" event } </script>
jQuery
If you are going to change event handlers at runtime, or if you need to attach several handlers to a single event, subscribe to the events using the on(eventName, eventHandler) method.
const hiddenEventHandler1 = function (e) { // First handler of the "hidden" event }; const hiddenEventHandler2 = function (e) { // Second handler of the "hidden" event }; $("#tooltipContainer").dxTooltip("instance") .on("hidden", hiddenEventHandler1) .on("hidden", hiddenEventHandler2);
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.