JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<div class="example">
<p>This jsFiddle demonstrates the use of the 'selector' option passed to the Twitter Bootstrap tooltip and popover JavaScript plugins.</p>
<p>The 'selector' option essentially allows you to run tooltips and popovers using jQuery's 'on' function, which means that you can allow dynamically added HTML with the correct selectors to trigger popups as if they were present in the originally loaded DOM. Without the selector option, only elements present in the initial DOM will trigger tooltips; any that are dynamically added will not.</p>
<p>Toggle the checkbox below and click the 'add new popover' button to observe the behavioral differences between using the selector option, and not using it.</p>
<p><label id="use-selector-label" class="checkbox"><input id="use-selector" type="checkbox" /> <span data-title="you must re-run this jsFiddle to change the selector option once you've started the demo">use selector option</span></label></p>
<pre id="with-selector-code">$('body').popover({
selector: '[rel=popover]'
});</pre>
<pre id="without-selector-code">$('[rel="popover"]').popover();</pre>
<p><a id="add-button" class="btn btn-small btn-success">add new popover</a></p>
<div class="buttons">
<hr />
<p><a class="btn btn-large btn-danger" rel="popover" data-title="Static" data-content="This button was specified in the initial HTML document" data-placement="top">hover for popover</a></p>
</div>
</div>
CSS
.example
{
margin: 8px 80px;
}
.buttons, pre
{
display: none;
}
JavaScript
function usingSelectorOption() {
return $('#use-selector').is(':checked');
}
function updateCodeView() {
$('#with-selector-code').toggle(usingSelectorOption());
$('#without-selector-code').toggle(!usingSelectorOption());
}
$(function() {
// update code view when checkbox is toggled
updateCodeView();
$('#use-selector').click(function() {
updateCodeView();
});
var startedDemo = false;
$('#add-button').click(function() {
// One-time initialization
if (!startedDemo) {
if (usingSelectorOption()) {
$('body').popover({
selector: '[rel=popover]'
});
} else {
$('[rel="popover"]').popover();
}
startedDemo = true;
}
// disable selector checkbox, put a tooltip on it, and show the buttons panel
$('#use-selector').attr('disabled', 'disabled');
$('#use-selector-label span').tooltip();
$('.buttons').show();
// add a new button that triggers (or doesn't) a popover, with the appropriate message
var does = usingSelectorOption() ? 'DOES' : 'does NOT';
$('<p><a class="btn btn-large btn-danger" rel="popover" data-title="Dynamic" data-content="This button was added dynamically by JavaScript" data-placement="top">notice that this ' + does + ' trigger a popup</a></p>').appendTo('.buttons');
});
});