I am using jquery UI and i am trying to show data attribute on the checkboxes
here is my html
<input class="checktip" data-home="Working from Home" data-office="Working from Office" type="checkbox" name="Monday" id="Monday">
and here it is the jquery COde i have
$(".checktip :checked").tooltip({
"classes": {"ui-tooltip": "uitooltip"},
"content": $(this).data("office")
});
$(".checktip").tooltip({
"classes": {"ui-tooltip": "uitooltip"},
"content": $(this).data("home")
});
but on hover of the elements, it is not showing me anything, is something wrong here
2
Answers
The documentation for jQuery tooltip says it will display the text in the
title
attribute of the element to which it’s applied. The element in your example doesn’t have atitle
attribute, so there’s nothing to display. That’s why your tooltip doesn’t show up.In the example below, I added a
title
to your<input>
element, so now the tooltip will show up when you hover.If you want to programmatically change the title, you can use the jQuery
.attr("title", "new value you want")
function.Consider the following.
This makes use of the
content
as a Function.This makes the tooltip more dynamic. It will not change when shown, yet after the check and once the mouse is moved back to the item.