How to enable Bootstrap tooltip on disabled button?

后端 未结 18 2502
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 23:18

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?

18条回答
  •  不知归路
    2020-11-29 00:08

    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!

    .disabled {
      pointer-events: all !important;
    }
    

    However you shouldn't use so general selector, because you will probably have to manually stop JavaScript event propagation way you know (e.preventDefault()).

提交回复
热议问题