sticky-sidebar
sticky-sidebar copied to clipboard
jQuery destroy method doesn't remove instance data on element
How to reproduce:
// initialize
$('.sidebar').stickySidebar();
// destroy
$('.sidebar').stickySidebar('destroy');
// initialize again
$('.sidebar').stickySidebar(); // ... and nothing happens
You can't reinitialize StickySidebar because $('.sidebar').data('stickySidebar')
contains previous instance;
.stickySidebar('destroy')
method should delete previous data;
I’m getting a similar issue in vanilla javascript world when working with Swup—have to destroy stickySidebar on each page load, but it fails.
i have this problem. have a solution?
You can just use jQuery's removeData function to get rid of the Sticky Sidebar data. Afterwards you're able to re-initialize it at your convenience.
$('.sidebar').stickySidebar('destroy');
$('.sidebar').removeData('stickySidebar');