By default, bootstrap Affix listens for scroll
and click
events on $(window)
using the .bs
, .affix
, and .data-api
namespaces.
$.off('.affix');
will remove all listeners in the .affix
namespace.
$(window).off('.affix');
will remove all listeners in the .affix
namespace from the window element. If you only have one Affix, and are affixing it to the window, it has the exact same effect as $.off('.affix');
Adding in the other namespaces makes it more specific, but unless you are using the .affix
namespace in your own code, the added specificity doesn't change anything. You don't want to remove the other namespaces independently of .affix
if you are using any other bootstrap elements.
$('.affix').off('.affix');
will not work because the listeners are not on the Affixed element, but on the target that element is Affixed to, i.e. the window.
pstenstrm is correct that there is no way to detect that an element is removed from the DOM, or injected for that matter. So if the code later re-injects the element, and you want to behave as an Affix again, you'll need to use the bootstrap JS api to call Affix again.