Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <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>
            
          
!
            
              body {
  padding: 30px;
}

h3 {
  line-height: 1.3;
}

.buttons, 
pre {
  display: none;
}

.btn-block {
  margin-bottom: 5px;
}
            
          
!
            
              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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console