I am trying to show tooltip for a disabled button. I am not sure if jquery events fire for disabled elements but I am trying to check if I can show tool tip for disabled items. My example is here
<p>Your age:
<input id="age" title="We ask for your age only for statistical purposes.">
</p>
<p>
<input type="button" title="This a test enabled button." value="hover me please">
</p>
<p>
<input type="button" disabled="disabled" title="This a test disabled button." value="hover me please"> </p>
$(function () {
$(document).tooltip({
position: {
my: "center bottom-20",
at: "center top",
using: function (position, feedback) {
$(this).css(position);
$("<div>")
.addClass("arrow")
.addClass(feedback.vertical)
.addClass(feedback.horizontal)
.appendTo(this);
}
}
});
});
By default, tooltips will not be displayed on disabled elements. However, you can enable this behavior by using the following steps: Add a disabled element like the button element into a div whose display style is set to inline-block . Set the pointer event as none for the disabled element (button) through CSS.
$(document). tooltip("disable"); $(document). tooltip("enable");
Tooltips are used with the element to display a title in the title box next to the element, when you hover the element with your mouse. Tooltips can be attached to any element. If you want to display tooltip, just add title attribute to input elements and the title attribute value will be used as tooltip.
To disable a button with jQuery you need to set the disabled property on the button using the prop method. For example $('. my-button'). prop('disabled', true) .
Looks like it's not guaranteed to work properly.
See the doc (http://api.jqueryui.com/tooltip/):
In general, disabled elements do not trigger any DOM events. Therefore, it is not possible to properly control tooltips for disabled elements, since we need to listen to events to determine when to show and hide the tooltip. As a result, jQuery UI does not guarantee any level of support for tooltips attached to disabled elements. Unfortunately, this means that if you require tooltips on disabled elements, you may end up with a mixture of native tooltips and jQuery UI tooltips.
EDIT: One way to go around this would be to, instead of setting the button to disabled
, style it so that it looks like it was disabled. If it's a simple button, that's all you have to do, if it's a submit
button, you'll also have to prevent it submitting the form.
EDIT #2: I gave the above workaround a try and it appears opacity:0.5
pretty much does the job (source: tjvantoll.com):
.disabled-button {
opacity: 0.5;
}
Here is your updated fiddle: http://jsfiddle.net/jkLzuh0o/3/
Instead of using disabled="disabled" you can use onclick="return false;" then the events still gets fired and the tooltip will show, but nothing happens when you click the button. This will also work on a checkbox :)
So instead of this:
<p>
<input type="button" disabled="disabled" title="This a test disabled button." value="hover me please">
</p>
You write this:
<p>
<input type="button" onclick="return false" title="This a test disabled button." value="hover me please">
</p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With