Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h3>Bootstrap tooltips &amp; popovers, and the <code>selector</code> option</h3>
    
    <p>This CodePen demonstrates the use of the <code>selector</code> option passed to the Bootstrap tooltip and popover JavaScript plugins.</p>

    <p>The <code>selector</code> option essentially allows you to run tooltips and popovers using jQuery's <code>on</code> 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>
    
    <hr>

    <div class="checkbox">
      <label id="use-selector-label">
        <input id="use-selector" type="checkbox">
        <span data-title="you must re-run this CodePen to change the selector option once you've started the demo">Use selector option</span>
      </label>
    </div>

<pre id="with-selector-code">
$('body').popover({
  selector: '.has-popover'
});
</pre>
      
<pre id="without-selector-code">
$('.has-popover').popover();
</pre>

    <button class="btn btn-primary" id="add-button">Add new popover</button>

    <div class="buttons">
      <hr>

      <button class="btn btn-block btn-success has-popover" data-title="Static" data-content="This button was specified in the initial HTML document" data-placement="top">Working popover</button>
    </div>
              
            
!

CSS

              
                body {
  padding: 30px;
}

h3 {
  line-height: 1.3;
}

.buttons, 
pre {
  display: none;
}

.btn-block {
  margin-bottom: 5px;
}
              
            
!

JS

              
                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: '.has-popover'
        });
      } else {
        $('.has-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 button = null;
    if (usingSelectorOption()) {
      button = $('<button class="btn btn-block btn-success has-popover" data-title="Dynamic" data-content="This button was added dynamically by JavaScript" data-placement="top">Working dynamically added button</button>');
    } else {
      button = $('<button class="btn btn-block btn-default has-popover" data-title="Dynamic" data-content="This button was added dynamically by JavaScript" data-placement="top">Non-working dynamically added button</button>');
    }

    button.appendTo('.buttons');
  });
});
              
            
!
999px

Console