I need to display a tooltip on disabled button and remove it on enabled button. Actually it works in reverse way.
What is the best way to invert this behaviour?
$('[rel=tooltip]').tooltip();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<hr>
<button class="btn" disabled rel="tooltip" data-title="Dieser Link führt zu Google">button disabled</button>
<button class="btn" rel="tooltip" data-title="Dieser Link führt zu Google">button not disabled</button>
Here is the demo: http://jsfiddle.net/BA4zM/68/
P.S.: I want to keep the attribute disabled.
Here is some working code: http://jsfiddle.net/mihaifm/W7XNU/200/
The idea is to add the tooltip to a parent element with the
selector
option, and then add/remove therel
attribute when enabling/disabling the button.You can't get the tool-tip to show on a disabled button. This is because disabled elements don't trigger any events, including the tool-tip. Your best bet would be to fake the button being disabled (so it looks and acts like its disabled), so you can then trigger the tool-tip.
Eg. Javascript:
Instead of just
$('[rel=tooltip]').tooltip();
HTML:
JSFiddle: http://jsfiddle.net/BA4zM/75/
This can be done via CSS. The "pointer-events" property is what's preventing the tooltip from appearing. You can get disabled buttons to display tooltip by overriding the "pointer-events" property set by bootstrap.
If you're desperate (like i was) for tooltips on checkboxes, textboxes and the like, then here is my hackey workaround:
Working examples: http://jsfiddle.net/WB6bM/11/
For what its worth, I believe tooltips on disabled form elements is very important to the UX. If you're preventing somebody from doing something, you should tell them why.
These workarounds are ugly. I've debugged the problem is that bootstrap automatically set CSS property pointer-events: none on disabled elements.
This magic property causes that JS is not able to handle any event on elements that matches CSS selector.
If you overwrite this property to default one, everything works like a charm, including tooltips!
However you shouldn't use so general selector, because you will probably have to manually stop JavaScript event propagation way you know (e.preventDefault()).
Try this example:
Tooltips must be initialized with
jQuery
: select the specified element and call thetooltip()
method inJavaScript
:Add
CSS
:And your html: