Replace HTML entities inside a Div

1

I have code html and I need to replace part of it with another html , this code is inside a div .

Code:

<div id="aba-per" class="et_pb_module et_pb_tabs tab-per et_pb_tabs_0">
    <ul class="et_pb_tabs_controls clearfix">
        <li class="et_pb_tab_0 et_pb_tab_active"><a href="#">Teste &rarr; Teste</a></li>
    </ul>
</div>

I want to replace &rarr; with <br> , that is, instead of showing the arrow I need the line to be broken.

    
asked by anonymous 17.02.2017 / 21:44

1 answer

1

It happens that &rarr; in the browser will be rendered with its corresponding character, in case →

What you can do is grab the content using innerHTML , make the change using replace , and assign the new text to the div element

function teste() {
  var texto = document.getElementById("aba-per").innerHTML;
  texto = texto.replace("→", "<br/>");
  document.getElementById("aba-per").innerHTML = texto;
}
<div id="aba-per" class="et_pb_module et_pb_tabs tab-per et_pb_tabs_0">
  <ul class="et_pb_tabs_controls clearfix">
    <li class="et_pb_tab_0 et_pb_tab_active"><a href="#">Teste &rarr; Teste</a></li>
  </ul>
</div>
<button onclick="teste()">teste</button>

Anyway, it seems like a duplicate of this question here: Replace the

17.02.2017 / 21:49