May 2017
Intermediate to advanced
448 pages
10h 10m
English
We've seen that the widget factory creates a new jQuery method, in our case called .tooltip(), that can be called with no arguments to apply the widget to a set of elements. There's much more that this method can do, though. When we give this method a string argument, it calls the method with the appropriate name.
One of the built-in methods is called destroy. Calling .tooltip('destroy') will remove the tooltip widget from the page. The widget factory does most of the work, but if we have modified parts of the document inside ._create() (as we have here, by creating the tooltip text <div>), we need to clean up after ourselves:
(($) => { $.widget('ljq.tooltip', { _create() { // ... }, destroy() { this._tooltipDiv.remove(); ...Read now
Unlock full access