I’ve tried solutions found on other similar threads, but can’t get them working.
I’ve got a bootstrap button that, when in a disabled state, should have a tooltip letting the user know why it’s disabled.
I understand that a button in disabled state has a CSS that prevents mouseover events from reaching the button element, and that there are workarounds for this.
What am I doing wrong in the below code?
// Grab button from DOM
let resultsBtn = document.getElementById("get-results-btn");
// if conditional is met, disable button
$(resultsBtn).prop("disabled", true);
// then, add tooltip
$(resultsBtn).attr("data-toggle", "tooltip");
$(resultsBtn).attr("title", "you may only submit this form once");
// add css rules to make tooltip work on disabled button
$(resultsBtn).css("pointer-events", "none");
/* ====================================== */
/* Button styling */
/* ====================================== */
#get-results-btn {
// insert styling rules for color, size, etc. here, plus the following rules:
cursor: pointer;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
pointer-events: none; ////// Added this based on [S/O thread][1]
}
#get-results-btn .btn[disabled] //// I pulled this line from [S/O thread][1], but I don't think the class applies to my code?
<button id="get-results-btn" class="btn standard-btn-style">
Get Results
</button>
2
Answers
Try this code:
Changes I made to your code:
Added a wrapper div to the button, so the wrapper can show the tooltip
You was added
pointer-events: none
to the wrong class. Corrected it.In javascript code, it should be
data-bs-toggle
notdata-toggle
.As per the documentation:
Example quoting from the documentation itself: