<span class="WorkingHours">
M,W,Th,F 7:30 AM - 4:00 PM <br />Tu 7:30 AM - 6:00 PM <br />
</span>
will be rendered as this
M,W,Th,F 7:30 AM - 4:00 PM <br />Tu 7:30 AM - 6:00 PM <br />
Now i need to replace the <br /> as an empty space before it is rendered??
I already asked a similar question, but i underestimated the trickiness of this..
I did this
$('.WorkingHours').text().replace(/<br \/>/g, " ");
didn’t work..can someone help me out of this?
Shouldn’t this work?
$('.WorkingHours').text().replace(/<br \>/g, " ");
This will work:
DEMO
In this case
.html()would return the HTML entities (<) whereas.text()returns the decoded characters (i.e.<). Given that,actually works as well but you still have to assign the result back to the element.
See also my previous answer.
Regarding replacing the last
<br />with a different character: It might be possible with regular expressions, but in that case, I would just parse the text as HTML and perform the same operation as I showed in my previous answer:DEMO