CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

15 January, 2019

JqueryUI - Tooltip

 Programing Coderfunda     January 15, 2019     JqueryUI, JqueryUI - Tooltip     No comments   

JqueryUI - Tooltip, JqueryUI, 

Tooltip widget of jQueryUI replaces the native tooltips. This widget adds new themes and allows for customization. First let us understand what tooltips are? Tooltips can be attached to any element. To display tooltips, just add title attribute to input elements and title attribute value will be used as tooltip. When you hover the element with your mouse, the title attribute is displayed in a little box next to the element.
jQueryUI provides tooltip() method to add tooltip to any element on which you want to display tooltip. This gives a fade animation by default to show and hide the tooltip, compared to just toggling the visibility.

Syntax

The tooltip() method can be used in two forms −
  • $(selector, context).tooltip (options) Method
  • $(selector, context).tooltip ("action", [params]) Method

$ (selector, context).tooltip (options) Method

The tooltip (options) method declares that a tooltip can be added to an HTML element. The options parameter is an object that specifies the behavior and appearance of the tooltip.

Syntax

$(selector, context).tooltip(options);
You can provide one or more options at a time using Javascript object. If there are more than one options to be provided then you will separate them using a comma as follows −
$(selector, context).tooltip({option1: value1, option2: value2..... });
The following table lists the different options that can be used with this method −
Sr.No.Option & Description
1content This option represents content of a tooltip. By default its value is function returning the title attribute.
2disabled This option when set to true disables the tooltip. By default its value is false.
3hide This option represents the animation effect when hiding the tooltip. By default its value is true.
4items This option indicates which items can show tooltips. By default its value is [title].
5position This option decides the position of the tooltip w.r.t the associated target element. By default its value is function returning the title attribute. Possible values are: my, at, of, collision, using, within.
6show This option represents how to animate the showing of tooltip. By default its value is true.
7tooltipClass This option is a class which can be added to the tooltip widget for tooltips such as warning or errors. By default its value is null.
8track This option when set to true, the tooltip follows/tracks the mouse. By default its value is false.
The following section will show you a few working examples of tooltip functionality.

Default Functionality

The following example demonstrates a simple example of tooltip functionality passing no parameters to the tooltip() method.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Tooltip functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- Javascript -->
<script>
$
(function() {
$
("#tooltip-1").tooltip();
$
("#tooltip-2").tooltip();
});
</script>
</head>

<body>
<!-- HTML -->
<label for = "name">Name:</label>
<input id = "tooltip-1" title = "Enter You name">
<p><a id = "tooltip-2" href = "#" title = "Nice tooltip">
I also have a tooltip
</a></p>
</body>
</html>
Let us save the above code in an HTML file tooltipexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −
In the above example, hover over the links above or use the tab key to cycle the focus on each element.

Use of Content, Track and Disabled

The following example shows the usage of three important options (a) content (b) track and (c) disabled in the tooltip function of JqueryUI.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Tooltip functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- Javascript -->
<script>
$
(function() {
$
( "#tooltip-3" ).tooltip({
content
: "<strong>Hi!</strong>",
track
:true
}),
$
( "#tooltip-4" ).tooltip({
disabled
: true
});
});
</script>
</head>

<body>
<!-- HTML -->
<label for = "name">Message:</label>
<input id = "tooltip-3" title = "tooltip"><br><br><br>
<label for = "name">Tooltip disabled for me:</label>
<input id = "tooltip-4" title = "tooltip">
</body>
</html>
Let us save the above code in an HTML file tooltipexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −
In the above example, the content of tooltip of first box is set using content option. You can also notice the tooltip follows the mouse. The tooltip for second input box is disabled.

Use of Position

The following example shows the usage of option position in the tooltip function of JqueryUI.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Tooltip functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- CSS -->
<style>
body
{
margin
-top: 100px;
}

.ui-tooltip-content::after, .ui-tooltip-content::before {
content
: "";
position
: absolute;
border
-style: solid;
display
: block;
left
: 90px;
}
.ui-tooltip-content::before {
bottom
: -10px;
border
-color: #AAA transparent;
border
-width: 10px 10px 0;
}
.ui-tooltip-content::after {
bottom
: -7px;
border
-color: white transparent;
border
-width: 10px 10px 0;
}
</style>

<!-- Javascript -->
<script>
$
(function() {
$
( "#tooltip-7" ).tooltip({
position
: {
my
: "center bottom",
at
: "center top-10",
collision
: "none"
}
});
});
</script>
</head>

<body>
<!-- HTML -->
<label for = "name">Enter Date of Birth:</label>
<input id = "tooltip-7" title = "Please use MM.DD.YY format.">
</body>
</html>
Let us save the above code in an HTML file tooltipexample.htm and open it in a standard browser which supports javascript, you must also see the following output. Now, you can play with the result −
In the above example the tooltip position is set on top of the input box.

$ (selector, context).tooltip ("action", [params]) Method

The tooltip (action, params) method can perform an action on the tooltip elements, such as disabling the tooltip. The action is specified as a string in the first argument and optionally, one or more params can be provided based on the given action.
Basically, here actions are nothing but they are jQuery methods which we can use in the form of string.

Syntax

$(selector, context).tooltip ("action", [params]);
The following table lists the actions for this method −
Sr.No.Action & Description
1close() This action closes the tooltip. This method does not accept any arguments.
2destroy() This action removes the tooltip functionality completely. This will return the element back to its pre-init state. This method does not accept any arguments.
3disable() This action deactivates the tooltip. This method does not accept any arguments.
4enable() This action activates the tooltip. This method does not accept any arguments.
5open() This action programmatically opens the tooltip. This method does not accept any arguments.
6option( optionName ) This action gets the value associated with optionName for the tooltip. This method does not accept any arguments.
7option() This action gets an object containing key/value pairs representing the current tooltip options hash. This method does not accept any arguments.
8option( optionName, value ) This action sets the value of the tooltip option associated with the specified optionName.
9option( options ) This action sets one or more options for tooltip.
10widget() This action returns a jQuery object containing the original element. This method does not accept any arguments.

Examples

Now let us see an example using the actions from the above table. The following example demonstrates the use of actions disable and enable.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Tooltip functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- Javascript -->
<script>
$
(function() {
$
("#tooltip-8").tooltip({
//use 'of' to link the tooltip to your specified input
position
: { of: '#myInput', my: 'left center', at: 'left center' },
}),
$
('#myBtn').click(function () {
$
('#tooltip-8').tooltip("open");
});
});
</script>
</head>

<body style = "padding:100px;">
<!-- HTML -->
<a id = "tooltip-8" title = "Message" href = "#"></a>
<input id = "myInput" type = "text" name = "myInput" value = "0" size = "7" />
<input id = "myBtn" type = "submit" name = "myBtn" value = "myBtn" class = "myBtn" />
</body>
</html>
Let us save the above code in an HTML file tooltipexample.htm and open it in a standard browser which supports javascript, you must also see the following output −
In the above example, click on myBtn button and a tooltip pops up.

Event Management on Tooltip elements

In addition to the tooltip (options) method which we saw in the previous sections, JqueryUI provides event methods as which gets triggered for a particular event. These event methods are listed below −
Sr.No.Event Method & Description
1create(event, ui) Triggered when the tooltip is created. Where event is of type Event, and ui is of type Object.
2close(event, ui) Triggered when the tooltip is closed. Usually triggers on focusout or mouseleave. Where event is of type Event, and ui is of type Object.
3open(event, ui) Triggered when the tooltip is displayed or shown. Usually triggered on focusin or mouseover. Where event is of type Event, and ui is of type Object.

Examples

The following example demonstrates event method usage during tooltip functionality. This example demonstrates use of open and close events.
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Tooltip functionality</title>
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
rel = "stylesheet">
<script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
<script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<!-- Javascript -->
<script>
$
(function() {
$
('.tooltip-9').tooltip({
items
: 'a.tooltip-9',
content
: 'Hello welcome…',
show
: "slideDown", // show immediately
open
: function(event, ui) {
ui
.tooltip.hover(
function () {
$
(this).fadeTo("slow", 0.5);
});
}
});
});
$
(function() {
$
('.tooltip-10').tooltip({
items
: 'a.tooltip-10',
content
: 'Welcome to TutorialsPoint…',
show
: "fold",
close
: function(event, ui) {
ui
.tooltip.hover(function() {
$
(this).stop(true).fadeTo(500, 1);
},
function() {
$
(this).fadeOut('500', function() {
$
(this).remove();
});
});
}
});
});
</script>
</head>

<body style = "padding:100px;">
<!-- HTML -->
<div id = "target">
<a href = "#" class = "tooltip-9">Hover over me!</a>
<a href = "#" class = "tooltip-10">Hover over me too!</a>
</div>
</body>
</html>
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook

Related Posts:

  • JqueryUI - TooltipJqueryUI - Tooltip, JqueryUI, Tooltip widget of jQueryUI replaces the native tooltips. This widget adds new themes and allows for customization.… Read More
  • JqueryUI - Tooltip JqueryUI - Tooltip, JqueryUI,  Tooltip widget of jQueryUI replaces the native tooltips. This widget adds new themes and allows for customizati… Read More
Newer Post Older Post Home

0 comments:

Post a Comment

Thanks

Meta

Popular Posts

  • Spring boot app (error: method getFirst()) failed to run at local machine, but can run on server
    The Spring boot app can run on the online server. Now, we want to replicate the same app at the local machine but the Spring boot jar file f...
  • Log activity in a Laravel app with Spatie/Laravel-Activitylog
      Requirements This package needs PHP 8.1+ and Laravel 9.0 or higher. The latest version of this package needs PHP 8.2+ and Laravel 8 or hig...
  • Failed to install 'cordova-plugin-firebase': CordovaError: Uh oh
    I had follow these steps to install an configure firebase to my cordova project for cloud messaging. https://medium.com/@felipepucinelli/how...
  • Laravel auth login with phone or email
          <?php     Laravel auth login with phone or email     <? php     namespace App \ Http \ Controllers \ Auth ;         use ...
  • Cashier package and Blade files
    I'm a little confused about this Cashier package. I installed it using the Laravel website (with composer), but noticed there's no...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

  • Failed to install 'cordova-plugin-firebase': CordovaError: Uh oh - 9/21/2024
  • pyspark XPath Query Returns Lists Omitting Missing Values Instead of Including None - 9/20/2024
  • SQL REPL from within Python/Sqlalchemy/Psychopg2 - 9/20/2024
  • MySql Explain with Tobias Petry - 9/20/2024
  • How to combine information from different devices into one common abstract virtual disk? [closed] - 9/20/2024

Laravel News

  • Improved Installation and Frontend Hooks in Laravel Echo 2.1 - 5/15/2025
  • Filter Model Attributes with Laravel's New except() Method - 5/13/2025
  • Arr::from() Method in Laravel 12.14 - 5/14/2025
  • Streamline API Resources with Laravel's Fluent Methods - 5/13/2025
  • Customize URL Handling with Laravel's Macroable URI Class - 5/13/2025

Copyright © 2025 CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda