If I check official documentation, I can see a property called HTML:
Name | Type | default | Description
----------------------------------------------------------------------------
html | boolean | false | Insert html into the tooltip.
If false, jquery's text method
will be used to insert content
into the dom. Use text if you're
worried about XSS attacks.
It says, "insert html into the tooltip", but the type is boolean. How can I use complex html inside a Tooltip?
This parameter is just about whether you are going to use complex html into the tooltip. Set it to
true
and then hit the html into thetitle
attribute of the tag.See this fiddle here - I've set the html attribute to true through the
data-html="true"
in the<a>
tag and then just added in the html ad hoc as an example.Just as normal, using
data-original-title
:Html:
Javascript:
The html parameter specifies how the tooltip text should be turned into DOM elements. By default Html code is escaped in tooltips to prevent XSS attacks. Say you display a username on your site and you show a small bio in a tooltip. If the html code isn't escaped and the user can edit the bio themselves they could inject malicious code.
The
html
data attribute does exactly what it says it does in the docs. Try this little example, no JavaScript necessary (broken into lines for clarification):JSFiddle demos:
Another solution to avoid inserting html into data-title is to create independant div with tooltip html content, and refer to this div when creating your tooltip :
This way you can create complex readable html content, and activate as many tooltips as you want.
live demo here on codepen
set "html" option to true if you want to have html into tooltip. Actual html is determined by option "title" (link's title attribute shouldn't be set)
Live sample