If you want to use the Bootstrap api data only in a specific part of your DOM tree, you can try moving the event handlers to another, common ancestor (s). This code works very well for me, but consider - as stated here - This approach uses the jQuery undocumented function to retrieve the event handlers assigned by the document object .
function moveBootstrapEventHandlersTo(target) { var eventHandlers = $._data(document, "events"); $.each(eventHandlers, function() { $.each(this, function() { $(target).on( this.origType + "." + this.namespace, this.selector, this.data, this.handler ); }); });
Now you can disable the default api data and enable it with some class name. Remember that you do not need to insert these elements. All events are bubbling, therefore - upon attachment - the same event handler is called several times.
<body> <div class="with-bs-data-api"> // bootstrap data api works here </div> <div class="some-other-class"> // but doesn't work here </div> <footer> <div class="with-bs-data-api"> // and here it works again </div> </footer> <script type="text/javascript"> moveBootstrapEventHandlersTo(".with-bs-data-api"); $(document).off('.data-api'); </script> </body>
source share