14

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.

Liam
  • 27,717
  • 28
  • 128
  • 190
Inventor
  • 485
  • 2
  • 7
  • 13

2 Answers2

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/

Pang
  • 9,564
  • 146
  • 81
  • 122
NoLifeKing
  • 1,909
  • 13
  • 27
  • 1
    Tested and works with: Firefox 42, Opera 39, IE11 please add comment if there is any browser that doesn't work – Nadu Aug 10 '16 at 12:22
  • this has always worked (where title was supported), early HTML documentation did a similar thing with the alt tag. – Jasen Aug 04 '17 at 04:02
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

Ana
  • 106
  • 1
  • 4