0

I want to add a list of users in title & each user has a line, I try this :

var favTitle;

for(var j=0;j<like_favs[1].length;j++)
    favTitle +=like_favs[1][j].username+"\n";

$("#Item").append('<i title="In favorite users : '+favTitle+'">Favorite</i>');

I've also tried "&#13;" and "&#10;" but it does not work everything is written in one line, please help by anyway to leave a line.

Anouar khaldi
  • 772
  • 6
  • 15

3 Answers3

2

Try adding a line break (<br>) at the end of each line.

$("#fav").append('<i title="In favorite users : '+favTitle+'">Item</i><br>');
Victoria Ruiz
  • 4,913
  • 3
  • 23
  • 40
  • This leaves a new line for each element `` But I want to display the `` element one time and the attr `title `contains a lines – Anouar khaldi Apr 08 '18 at 22:59
  • HTML attributes are not meant to be visually formatted. There's a way explained here: https://stackoverflow.com/questions/246438/newline-in-td-title It might not display reliably in different browsers. You're better off building a tooltip that you can actually format with HTML and css. – Victoria Ruiz Apr 08 '18 at 23:05
0

&#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>
Kirill Simonov
  • 8,257
  • 3
  • 18
  • 42
0

I think this should work, otherwise, you should update your browser:

var favTitle = '';
for(var j=0;j<like_favs[1].length;j++)
    favTitle +=like_favs[1][j].username+"&#13;";

$("#Item").append('<i title="In favorite users : &#13;'+favTitle+'">Favorite</i>');
CryptoBird
  • 508
  • 1
  • 5
  • 22