abouolia/sticky-sidebar

jQuery destroy method doesn't remove instance data on element

RomanAkhma opened this issue · 3 comments

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');