Rama Lingam Rama Lingam - 4 months ago 18
jQuery Question

br tag is not working while replace the content from textarea to DIV using JQUERY text function

The br tag is not working on DIV.
I am getting the message from Update Content:

textarea
field.
The message have the 2 lines like "Rama" next line "Lingam".
But the result is "Rama
Lingam" by
$("#editQuotesRowLabel_Q_013").text(replaceContent);


How to make a new line in DIV?

Here is my code:

function updateQuotes(){
var weg_quotes = $("#weg_quotes_Q_013").val();
replaceContent = weg_quotes.replace("\n", "<br>", "g");
$("#editQuotesRowLabel_Q_013").text(replaceContent);
}


Update Content: <textarea placeholder="Update your content..." id="weg_quotes_Q_013" name="weg_quotes" cols="80" rows="3" class="appQuotesTextarea" maxlength="200" required=""></textarea>
<button onclick="updateQuotes()" id="Q_013" name="update-btn" class="appQuotesBtn">Update</button>

<div id="editQuotesRowLabel_Q_013" class="appQuotesLabel">
This is content div.
</div>

Answer

To insert HTML content using jquery you need to use .html() instead of .text(). So in your case you end up with :

 $("#editQuotesRowLabel_Q_013").html(replaceContent);
 //                              |_ use html() instead of text()

Source :