Html Inside Twitter Bootstrap Popover
To embed HTML in a Bootstrap popover, enable the html
option. You then start loading content
with HTML tags:
This snippet gives life to all elements carrying data-toggle="popover"
to accept HTML content inside.
Get dynamic with your content
A static, boring popover? Not here! We can make content dynamic for popovers:
In this trick, we use a function to content
. It pulls HTML from a hidden div or generates it on-the-fly.
Say no to content spoofing
While loading HTML content into a popover, be mindful of security. We don't want to be the party where XSS attacks sneak in. Ensure you sanitize the content:
Customize your triggers and position occupiers
Don't like the defaults? With data-trigger
and data-placement
, you can don the customization cape:
Specify all the things: content, title tags
Keep your code neat with data-content
and data-original-title
or title
:
data-container="body"
helps keep your popovers snuggled within the body, preventing overflow issues.
Tidy up your content
Here's a tip on making your popovers look neat: Hook the content in hidden divs:
Error checking, because everybody makes mistakes
Whoops, did I forget to initialize the popovers? Always cross-validate your attributes and bring up the popovers post any related JavaScript code:
And the golden rule—always test. Your popover could have stage fright in some browsers!
Tips & Tricks (top-hat, rabbit, and wand not included)
Wave your hands, make your content dynamic with JS
Add a magic touch to your popover's content:
Anchor tags, not your ship's anchor
While using <a>
tags, set href
with care and event.preventDefault()
to keep them under control within the popover.
Was this article helpful?