user6135434
user6135434

Reputation:

jQuery append text in but in a new line

I am trying to append a new line using this this code. I have tried \n and only \ but no solution. What can I do now?

function infC(name) {
    jQuery("#dialog").text(information_by_equipment[name][1]).append(information_by_equipment[name][2]);
    event.stopPropagation();
}

Upvotes: 7

Views: 18736

Answers (3)

Isuru Dilshan
Isuru Dilshan

Reputation: 829

If the above solutions are not working try this one.

jQuery("#dialog")
  .text(information_by_equipment[name][1])
  .append("
" + information_by_equipment[name][2]);


 Line Feed and 
 Carriage Return

Upvotes: 0

Simply Me
Simply Me

Reputation: 1587

$(document).ready(function(){
    $("#dialog").append((information_by_equipment[name][1] + "<br>" + information_by_equipment[name][2]);
});

This should solve your problem. Simply add a <br> to enter a new line between your "lines".

Upvotes: 1

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167250

The .append() appends HTML. You need to use <br />:

jQuery("#dialog")
  .text(information_by_equipment[name][1])
  .append("<br />" + information_by_equipment[name][2]);

Upvotes: 10

Related Questions