Pergunta

This seems like it would be a common case, but I cannot find any information on it. Perhaps it's something I'm just missing.

All tooltips are working as expected. However, we load some content dynamically, so it gets injected after the tooltip method is called.

What is the best way to get tooltips applied to new content which is injected after pageload?

UPDATE To be clear, I am not looking for how to inject dynamic content into a tooltip. I am looking for how to get the tooltip plugin to notice new content injected into the page.

Thanks

Foi útil?

Solução

I would do like this: Make your tooltip-options reusable like this:

var options = { content: "Awesome title!", ... }

Then make your first-tooltip-init on page load:

$('.someclass').tooltip(options);

After adding some new elements dynamically do like this:

$(dynamicallyaddedcontent).tooltip(options);

Outras dicas

The jquery tooltip is a simple div, and as such you can inject content the same way you do with normal divs, using methods like JQuery's append. Best explained here.

EDIT: To match your edit I suppose you can find your answer here. Look at the second answer (the one with the more upvotes, not the accepted solution since it's deprecated)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top