1

When I dynamically add right html markup to the DOM bootstrap hooks up right plugin on new element. How does it do this?

If I have a markup

<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu"> <li><a tabindex="-1" href="#">Action</a></li> <li class="divider"></li> <li><a tabindex="-1" href="#">Separated link</a></li> </ul> 

Bootstrap will make from it dropdown element (hooks up dropdown plugin). How does it do it? Does it do it dynamically? (if I add markup during runtime?)

1
  • could you please clarify your question? Commented Oct 29, 2012 at 7:10

1 Answer 1

1

It does so by hooking to document ready event (or window load) and then either setting event listeners or initializing the components. For example, Affix plugin is being searched by its data-spy="affix" attribute. As for Typeahead plugin, it gets initialized on first focus event.

Sign up to request clarification or add additional context in comments.

2 Comments

Does it hook plugins dynamically on newly added markup during runtime?
In most cases it does. Bootstrap plugins delegates event listening to body element, not the targeted elements itself. This way it can always handle dynamically added controls. It effectively initializes the plugin when the user first interacts with it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.