Question

To make sure that the items that are dynamically created are intercepted by the events using the method .on:

$('body').on('click', '.element',...

But if I wanted to intercept the new elements of a plugin, how can you do?

For example using the plugin tooltip bootstrap:

jsFiddle

if I create a new element, to ensure that this is intercepted by the tooltip plugin I have to call again:

$('a').tooltip();

This is a system not as good as I have to continually repeat code for every new element that I create ..

So there is a way to refresh the elements?

Was it helpful?

Solution

You can use selector delegation option.

See the docs: http://twitter.github.io/bootstrap/javascript.html#tooltips

$('body').tooltip({
    placement:'bottom',
    selector: '[data-toggle=tooltip]'
});

Demo: jsFiddle

OTHER TIPS

Take a look at this fiddle, i'm using:

$('body').on('mouseenter', 'a', function(){$(this).tooltip();});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top