ZeroZek
ZeroZek

Reputation: 319

Add new line using jQuery concat

Through ajax response I'm passing array data from controller to blade.

enter image description here

On Ajax success I'm looping through array with 2 elements and concatenating string to display later on in my bootstrap popover.

success: function (data) {
                var content = "";
                var num = 1;
                for (var i = 0; i < data.length; i++) {
                    content = content.concat(num + "." + " " + data[i]);
                    num++;
                }
                $("#content").popover({content: content});
            }

Result:

enter image description here

I would like to add new line, so that each item or "artikel" would be displayed in new line e.g. :

1.Artikel...
2.Artikel...

I tried to add "\n" (as below) or html break but nothing works, it only appends as string.

content = content.concat(num + "." + " " + data[i] + "\n");

Upvotes: 1

Views: 549

Answers (1)

Anurag Srivastava
Anurag Srivastava

Reputation: 14413

Use this:

content.concat(num + "." + " " + data[i] + "<br/>");

And this:

$("#content").popover({ html:true, content: content });

Upvotes: 2

Related Questions