Reputation: 53
I'm trying to append a line break to a line of text I'm loading from an xml page using the following code:
$("#questionNumber").text(questionInARow).append('<br>');
The text is loading okay, but the append is being ignored. I've also tried this:
$("#questionNumber").text(questionInARow).html("<br>");
and this is ignored likewise. Is my syntax wrong, or my method just bad?
Thank you in advance.
Upvotes: 4
Views: 15618
Reputation: 81
This worked for me
success: function (data) {
$("#textArea").html(data["Name"] + "\n" + data["Address"] + "\n" + data["Phone"]);
},
You can use like this
$("#textArea").html("Line 1 Text \n Line 2 Text \n Line 3 Text");
Upvotes: 0
Reputation: 268344
It's much simpler than you think:
$("#questionNumber").html( questionInARow + "<br/>" );
Fiddle: http://jsfiddle.net/8jyqH/
Upvotes: 1
Reputation: 3758
Markup
<div id='temp'></div>
JS
$('#temp').text("hello").html($("#temp").html() + "<br/> how do you do? "); //This is one way
$('#temp').html("hello").append("<br/> how do you do?"); //Yet another way using the 'append' method.
Upvotes: 3
Reputation: 571
It seems that
<br/>
is a tag. But you used .html() and .append() methods of jQuery, both of them are inserting contents into content node.
Upvotes: 0