by Tom Millard

Bind events on dynamic content using jQuery

javascript - jquery

When you inject a view into a container any jQuery click event within that view will need to be bound again.

The best way to bind actions to dynamic content when using jQuery is to listen out for new DOM elements and bind on them when they appear.

$('#somecontainer').on('click' ,'.js-tool-tip', actionListenedToolTip);

In this piece of code any html injected into '#somecontainer' which has the class '.js-tool-tip' will have our click event bound to it.