sticky-sidebar icon indicating copy to clipboard operation
sticky-sidebar copied to clipboard

jQuery destroy method doesn't remove instance data on element

Open RomanAkhma opened this issue 5 years ago • 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;

RomanAkhma avatar May 27 '19 13:05 RomanAkhma

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.

piotrfonte avatar Dec 02 '19 12:12 piotrfonte

i have this problem. have a solution?

aykutyilmaz37 avatar Feb 01 '20 12:02 aykutyilmaz37

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

jellehermsen avatar Mar 02 '20 11:03 jellehermsen