16

i would like to find out how to add a break in the title attribute, i would like to have breaks in the title attribute to differentiate the names. how can i add a break in the title attribute?

i have something like this

<p title="this is a description of the some text <br> and further description">Some Text</p>

what comes out is:image showing <br> in stead of braking.

6
  • 3
    The title is plain text. It does not render HTML tags. Commented Nov 14, 2013 at 15:45
  • You could possibly use some external tool like the Jquery UI tooltip Commented Nov 14, 2013 at 15:48
  • 1
    @Liam: You're right. In that case, voting to close as dupe. Commented Nov 14, 2013 at 15:50
  • 8
    Just use the entity code &#013; for a linebreak in a title attribute. Commented Feb 22, 2016 at 15:26
  • 1
    @Aliti : Thanks a lot, works like a charm. Commented Apr 3, 2019 at 9:29

2 Answers 2

10

If you add a new line where you want line breaks, it works on SOME browsers, but not all.

Example:

div { background-color: #c3c3c3; display: block; width: 100px; height: 100px; }
<div title="This is a text
    Second line
    Third line!">Contents</div>

JSFiddle:
http://jsfiddle.net/g5CGh/

Sign up to request clarification or add additional context in comments.

2 Comments

Tested and works with: Firefox 42, Opera 39, IE11 please add comment if there is any browser that doesn't work
this has always worked (where title was supported), early HTML documentation did a similar thing with the alt tag.
6

In the title text replace <br> for &lt;br /&gt;

<p title="this is a description of the some text &lt;br /&gt; and further description">Some Text</p>

And now replace <br /> with a line break \n (jquery):

<script>
    $(document).ready(function(){
    $('p').each(function(){
        var a = $(this).attr('title');
        var b = a.replace('<br />','\n');
        $(this).attr('title', b);
    });
    });
</script>

Hope I've helped you

2 Comments

Or you may Add "\n" in your title wherever you want a line-break.
it s not necessary to use "\n" in my case

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.