Reputation: 15626
I have a paragraph
<p>hello<br>wor l d</p>
then I want show the paragraph's html in another textarea use jquery html() method
$(function () {
var temp = $('p').html();
$("textarea").html(temp);
});
but the result is
hello<br>wor l d
Why does <br>
not work? I didn't change any html.
Upvotes: 0
Views: 131
Reputation: 8407
? isn´t that clear? you are requesting the html and this one is pasted into the textbox? You will have to replace the br into linebrakes, like "\n"
var temp = $('p').html();
$("#tt").html(temp.replace(/<br\s*(\/|)>/gi, '\n'));
Upvotes: 3
Reputation: 53198
Yes, if you want to output it as displayed, the following code should help:
$(function() {
var temp = $('p').html();
var textareaval = temp.replace("<br>", "\n");
textareaval = textareaval.replace("<br />", "\n");
$('textarea').html(textareaval);
});
See the jsFiddle here: http://jsfiddle.net/6adgA/
Upvotes: 0