Add line break within tooltips

后端 未结 27 2306
北恋
北恋 2020-11-28 02:23

How can line breaks be added within a HTML tooltip?

I tried using
and \\n within the tooltip as follows:



        
相关标签:
27条回答
  • 2020-11-28 02:45

    Well if you are using Jquery Tooltip utility, then in "jquery-ui.js" Javascript file find following text:

    tooltip.find(".ui-tooltip-content").html(content);
    

    and put above that

    content=content.replace(/\&lt;/g,'<').replace(/\&gt;/g,'>');
    

    I hope this will also work for you.

    0 讨论(0)
  • 2020-11-28 02:45

    if you are using jquery-ui 1.11.4:

    var tooltip = $.widget( "ui.tooltip", {
        version: "1.11.4",
        options: {
            content: function() {
                // support: IE<9, Opera in jQuery <1.7
                // .text() can't accept undefined, so coerce to a string
                var title = $( this ).attr( "title" ) || "";
                // Escape title, since we're going from an attribute to raw HTML
    Replace-->  //return $( "<a>" ).text( title ).html();
    by -->      return $( "<a>" ).html( title );
                 },
    
    0 讨论(0)
  • 2020-11-28 02:45

    use &#13; should work (I've tested in Chrome, Firefox and Edge):

    let users = [{username: 'user1'}, {username: 'user2'}, {username: 'user3'}];
    let favTitle = '';
    for(let j = 0; j < users.length; j++)
        favTitle += users[j].username + "&#13;";
    
    $("#item").append('<i title="In favorite users: &#13;' + favTitle + '">Favorite</i>');
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id = item></div>

    0 讨论(0)
  • 2020-11-28 02:45

    This css will help you.

        .tooltip {
          word-break: break-all;
        }
    
    or if you want in one line
    
        .tooltip-inner {
          max-width: 100%;
        }
    
    
    0 讨论(0)
  • 2020-11-28 02:48

    Grater than Jquery UI 1.10 is not support to use html tag inside of the title attribute because its not valid html.

    So the alternative solution is to use tooltip content option. Refer - http://api.jqueryui.com/tooltip/#option-content

    0 讨论(0)
  • 2020-11-28 02:49

    Just add data-html="true"

    <a href="#" title="Some long text <br/> Second line text \n Third line text" data-html="true">Hover me</a>
    
    0 讨论(0)
提交回复
热议问题