First of all, if you want to use HTML inside the content you need to set the HTML option to true:
$('.danger').popover({ html : true});
Then you have two options to set the content for a Popover
- Use the data-content attribute. This is the default option.
- Use a custom JS function which returns the HTML content.
Using data-content:
You need to escape the HTML content, something like this:
<a class='danger' data-placement='above'
data-content="<div>This is your div content</div>"
title="Title" href='#'>Click</a>
You can either escape the HTML manually or use a function. I don't know about PHP but in Rails we use *html_safe*.
Using a JS function:
If you do this, you have several options. The easiest I think is to put your div content hidden wherever you want and then write a function to pass its content to popover. Something like this:
$(document).ready(function(){
$('.danger').popover({
html : true,
content: function() {
return $('#popover_content_wrapper').html();
}
});
});
And then your HTML looks like this:
<a class='danger' data-placement='above' title="Popover Title" href='#'>Click</a>
<div id="popover_content_wrapper" style="display: none">
<div>This is your div content</div>
</div>
Hope it helps!
PS: I've had some troubles when using popover and not setting the title attribute... so, remember to always set the title.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…