Many Bootstrap plugins become functional simply by adding certain data-*="xzy"
attributes to elements (in real-time).
For example, just include data-toggle="collapse"
in an anchor tag and Bootstrap Collapse will work immediately. Check out the demo https://jsfiddle.net/4n5zrkpb/.
I am curious about:
- What technology is used behind this functionality? (I heard they do not rely on mutation events or use
MutationObserver
.) - Can I implement it myself ;-)
UPDATE: I do not want to deal with Event binding on dynamically created elements?. Originally, my goal was to know when new elements were dynamically created! However, the Bootstrap method seems more convenient and compatible: It only notifies if there is some user interaction (such as listening to all click events).