Dynamic Tooltip content with HTML elements

17 Feb 20222 minutes to read

The Tooltip component loads HTML tags using the content template.

The HTML tags such as <div>, <span>, bold, italic, underline, etc., can be used. Style attributes can also be applied with HTML tags.

Here, Bold, Italic, Underline, and Anchor tags are used.

When using HTML elements as content to Tooltip make the content element display: none, then from the
beforeRender
event we can make the element visible again using below code.

    document.getElementById('content').style.display = 'block';
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Popups
@{
    var content = "<div id=\"tooltip\">" +
"        <h2>HTML Tags</h2>" +
"        Through templates, <b><span style=\"color:#e3165b\">tooltip content</span></b> can be loaded with <u><i> inline HTML, images, iframe, videos, maps </i></u>. A title can be added to the content" +
"    </div>";


}
<div id="container">
    @Html.EJS().Tooltip("target").CssClass("customtooltip").Content(content).ContentTemplate(@<div id="tooltipContent">
    <div class="content">
        <button class="text" id="Title">HTML(With Title)</button>
    </div>
</div>).Render()
</div>


<style>
    #tooltipContent table {
        margin: 0 auto;
    }

    #tooltipContent {
        display: inline-block;
        position: relative;
        left: 50%;
        transform: translateX(-50%);
        margin-top: 100px;
    }

    .text {
        text-transform: capitalize;
        width: 155px;
    }

    .header {
        font-family: "Arial Black", Gadget, sans-serif;
        font-size: 12px;
        padding-bottom: 2px;
        margin: 4px -7px 7px -7px;
        padding-right: 5px;
        padding-left: 6px;
        font-weight: bold;
        height: 18px;
        border-bottom: 1px solid white;
    }

    .e-tooltip-css.e-tooltip-wrap .e-tip-content {
        padding: 0 10px 10px 10px;
    }
</style>
public ActionResult TooltipView()
{
    return View();
}