Getting started with EJ2 JavaScript Tooltip
14 Sep 20263 minutes to read
This section explains the steps required to create a simple Essential® JS 2 Tooltip and demonstrate the basic usage of the Tooltip control in a JavaScript application.
Dependencies
The list of dependencies required to use the Tooltip component in your application is given below:
|-- @syncfusion/ej2-popups
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-buttonsSetup for local environment
Refer to the following steps to set up your local environment.
Step 1: Create a root folder named my-app for your application.
Step 2: Create a my-app/resources folder to store local scripts and styles files.
Step 3: Open Visual Studio Code and create my-app/index.js and my-app/index.html files to initialize the Essential® JS 2 Tooltip control.
Control Initialization
The Essential® JS 2 JavaScript controls can be initialized by using below css styles and Scripts
Add Syncfusion® Tooltip CSS Styles and Scripts
Include the following CSS and JavaScript files from CDN in the <head> section of the index.html file. The ej2-base, ej2-buttons script is the required dependency package for the Tooltip component.
Styles(CSS):
https://unpkg.com/@syncfusion/ej2-bootstrap5.3-theme/styles/tooltip/index.cssScripts (javascript):
https://cdn.syncfusion.com/ej2/35.1.37/ej2-base/dist/global/ej2-base.min.js
https://cdn.syncfusion.com/ej2/35.1.37/ej2-buttons/dist/global/ej2-buttons.min.jsAdding Tooltip component to the application
Add the Tooltip element and initiate the Essential® JS 2 Tooltip control in the index.html by using following code.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Essential JS 2 Tooltip</title>
<link href="https://unpkg.com/@syncfusion/ej2-bootstrap5.3-theme/styles/tooltip/index.css" rel="stylesheet" />
<!-- Essential JS 2 Tooltip's global script -->
<script src="//cdn.syncfusion.com/ej2/21.2.3/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<!-- Add the HTML span element -->
<div id='container'>
<div style="display: inline-block; position: relative; left: 50%;top: 100px;transform: translateX(-50%);">
<span id='target'></span>
</div>
</div>
<script>
//Initialize Essential JS 2 JavaScript Tooltip component
var tooltip = new ej.popups.Tooltip({
width: '150px',
height: '40px',
content: 'Tooltip with specific width and height'
});
tooltip.appendTo('#target');
var button = new ej.buttons.Button({
content: 'Show Tooltip'
});
button.appendTo('#target');
</script>
</body>
</html>