In my <td>
tag, there are few -.
in it. What I want to do is, put <br>
tag in front of this specific word. I did replace()
function but it changed just one -.
How do I find all instances of -.
?
Original Text
Lorem Ipsum is simply dummy text of the printing and typesetting industry. -.Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. -.It has survived not only five centuries, but also the leap into electronic typesetting.
What I want
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
-. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
-. It has survived not only five centuries, but also the leap into electronic typesetting.
This is my Code example
<table class="Notice">
<thead>
<tr>
<th>Name</th>
<th>Number</th>
</tr>
<thead>
<tbody>
<tr>
<td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. -.Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. -.It has survived not only five centuries, but also the leap into electronic typesetting.</td>
</tr>
</tbody>
</table>
Javascript
$('td:contains("-.")').html(function (i, htm) {
return htm.replace(/-./g, "<br>-.");
});
Solution
I found my mistake - I didn't do 'every' word. So I used the each()
function, and it works perfectly!
$('td:contains("-.")').each(function () {
$(this).html($(this).html().replace(/-./g, "<br>-."));
});
tag. – naanace Mar 10 '15 at 05:30