-
-
Save AleeRojas/509173e841b6e1a14b641af40535f5ad to your computer and use it in GitHub Desktop.
Bootstrap 4 - Load Popover Content From DOM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="unique-id" style="display:none;"> | |
<div class="popover-heading">This is a heading</div> | |
<div class="popover-body">This is HTML content that will be loaded inside a </div> | |
</div> | |
<span tabindex="0" role="button" data-toggle="popover" data-placement="bottom" data-popover-content="#unique-id"> | |
Click me to load a popover | |
</span> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
|-------------------------------------------------------------------------- | |
| Bootstrap 4 - Load Popover Content From DOM | |
|-------------------------------------------------------------------------- | |
| | |
| A quick JavaScript snippet that lets you dynamically load the content of | |
| a Bootstrap 4 popover from another HTML element in the DOM by making use | |
| of a data-popover-content attribute to reference a selector. | |
| | |
*/ | |
$(function(){ | |
$("[data-toggle=popover]").popover({ | |
html : true, | |
content: function() { | |
var content = $(this).attr("data-popover-content"); | |
return $(content).children(".popover-body").html(); | |
}, | |
title: function() { | |
var title = $(this).attr("data-popover-content"); | |
return $(title).children(".popover-heading").html(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment