I am trying to replace all dashes(-) by a "br" but it gives me issues.
I have tried
var strNewString = $('.member__designation').html().replace(/-/g,'<br>'); $('.member__designation').html(strNewString);
Here is the html
Before applying the code above
After applying the code above
2
You likely want
$('.member__designation').each(function() { this.textContent = this.textContent.replace(/-/g,'<br>') })
assuming $(‘.member__designation’) only has text and not html
IF there is only SIMPLE HTML like <b> then do
<b>
$('.member__designation').each(function() { this.innerHTML = this.innerHTML.replace(/-/g,'<br>') })
It looks like you grab all elements with class .member__designation and you replace them with whatever your regex grabs. I think you must change your implementation
.member__designation
Click here to cancel reply.
2
Answers
You likely want
assuming $(‘.member__designation’) only has text and not html
IF there is only SIMPLE HTML like
<b>
then doIt looks like you grab all elements with class
.member__designation
and you replace them with whatever your regex grabs. I think you must change your implementation