JavaScript/jQuery Tooltip - Getting Started

NOTE
Before you start the tutorial, ensure DevExtreme is installed in your application.

Tooltip is a UI component that allows you to display information over a specific element in your application.

This tutorial guides you through the following steps:

  • Add a Tooltip to a page and configure core component settings.
  • Customize Tooltip appearance.

The following live example demonstrates the result:

Embedded applications are not available for the selected DevExtreme version (v25.1).
We recommend that you upgrade to the most recent version of DevExtreme to access the latest features, bug fixes, and security updates.

Each section in this tutorial describes a single configuration step. You can find the complete source code in the following GitHub repository:

View on GitHub

Create and Configure Tooltip

Add DevExtreme to your jQuery application and use the code below to create a Tooltip. To display the component, specify a target and define the showEvent or visible property.

index.js
index.html
  • $(function() {
  • $('#tooltip').dxTooltip({
  • target: '#target',
  • showEvent: 'mouseenter',
  • });
  • });
  • <html>
  • <head>
  • <!-- ... -->
  • <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  • <link rel="stylesheet" href="https://cdn3.devexpress.com/jslib/25.1.15/css/dx.light.css">
  • <script type="text/javascript" src="https://cdn3.devexpress.com/jslib/25.1.15/js/dx.all.js"></script>
  • <script type="text/javascript" src="index.js"></script>
  • </head>
  • <body class="dx-viewport">
  • <div id="tooltip"></div>
  • </body>
  • </html>

This example creates three Button components and assigns Tooltips to them. Button ID attributes are specified as Tooltip targets. Additionally, this example configures the hideEvent property for all Tooltips:

index.js
index.html
  • $(function() {
  • $('#like').dxButton({
  • icon: 'like',
  • });
  •  
  • $('#like-tooltip').dxTooltip({
  • target: '#like',
  • showEvent: 'mouseenter',
  • hideEvent: 'mouseleave',
  • });
  •  
  • $('#trash').dxButton({
  • icon: 'trash',
  • });
  •  
  • $('#trash-tooltip').dxTooltip({
  • target: '#trash',
  • showEvent: 'mouseenter',
  • hideEvent: 'mouseleave',
  • });
  •  
  • $('#info').dxButton({
  • icon: 'info',
  • });
  •  
  • $('#info-tooltip').dxTooltip({
  • target: '#info',
  • showEvent: 'mouseenter',
  • hideEvent: 'mouseleave',
  • });
  • });
  • <body class="dx-viewport">
  • <div class="main-container">
  • <div class="buttons">
  • <div id="like"></div>
  • <div id="trash"></div>
  • <div id="info"></div>
  • </div>
  • <div class="tooltips">
  • <div id="like-tooltip"></div>
  • <div id="trash-tooltip"></div>
  • <div id="info-tooltip"></div>
  • </div>
  • </div>
  • </body>

Customize Tooltip

To customize Tooltip content, specify contentTemplate. If you assign a string to this property, Tooltip displays plain text in its container:

index.js
  • $(function() {
  • $('#like-tooltip').dxTooltip({
  • contentTemplate: 'like'
  • });
  •  
  • $('#trash-tooltip').dxTooltip({
  • contentTemplate() {
  • return $('<div>')
  • .addClass('red-tooltip')
  • .text('Delete');
  • },
  • });
  •  
  • $('#info-tooltip').dxTooltip({
  • contentTemplate() {
  • return $('<div>')
  • .addClass('blue-tooltip')
  • .text('Info');
  • },
  • });
  • })

You can use CSS to customize the Tooltip's appearance. The code snippets above assigned CSS classes to all tooltips. This example defines those styles (.red-tooltip and .blue-tooltip):

index.css
  • .dx-overlay-content:has(.blue-tooltip),
  • .dx-overlay-content:has(.blue-tooltip) .dx-popover-arrow::after {
  • background-color: #0f6cbd;
  • color: white;
  • }
  •  
  • .dx-overlay-content:has(.red-tooltip),
  • .dx-overlay-content:has(.red-tooltip) .dx-popover-arrow::after {
  • background-color: #d13438;
  • color: white;
  • }
See Also