Reputation: 21
I'm trying to change a text in the div tag "a/b" to "b/c" which would also maintain the new line that I had set up in the HTML using the break tag. Right now it replaces the text, but I want the second line to be place under the first line.
$(".text_div").text(function () {
return "<br />" + $(this).text().replace("a/b", "b/c");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="text_div">
This div contains some text.<br />
This is a a/b.
</div>
Upvotes: 0
Views: 21
Reputation: 19573
use .html()
instead of text if you want to keep the line breaks
$(".text_div").html(function () {
return $(this).html().replace("a/b", "b/c");
});
Upvotes: 1