I need to display a tooltip on a disabled button and remove it on an enabled button. Currently, it works in reverse.
What is the best way to invert this behaviour?
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.
.btn.disabled {
pointer-events: auto;
}
In my case, none of the above solutions worked. I found that it's easier to overlap the disabled button using an absolute element as:
<div rel="tooltip" title="I workz" class="wrap">
<div class="overlap"></div>
<button>I workz</button>
</div>
<div rel="tooltip" title="Boo!!" class="wrap poptooltip">
<div class="overlap"></div>
<button disabled>I workz disabled</button>
</div>
.wrap {
display: inline-block;
position: relative;
}
.overlap {
display: none
}
.poptooltip .overlap {
display: block;
position: absolute;
height: 100%;
width: 100%;
z-index: 1000;
}
Demo
I finally solved this problem, at least with Safari, by putting "pointer-events: auto" before "disabled". The reverse order didn't work.
Try this example:
Tooltips must be initialized with jQuery
: select the specified element and call the tooltip()
method in JavaScript
:
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
});
Add CSS
:
.tool-tip {
display: inline-block;
}
.tool-tip [disabled] {
pointer-events: none;
}
And your html:
<span class="tool-tip" data-toggle="tooltip" data-placement="bottom" title="I am Tooltip">
<button disabled="disabled">I am disabled</button>
</span>
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:
$('[rel=tooltip].disabled').tooltip();
$('[rel=tooltip].disabled').bind('click', function(){
return false;
});
Instead of just $('[rel=tooltip]').tooltip();
HTML:
<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>
JSFiddle: http://jsfiddle.net/BA4zM/75/
Working code for Bootstrap 3.3.6
Javascript:
$('body').tooltip({
selector: '[data-toggle="tooltip"]'
});
$(".btn").click(function(e) {
if ($(this).hasClass("disabled")){
e.preventDefault();
}
});
CSS:
a.btn.disabled, fieldset[disabled] a.btn {
pointer-events: auto;
}