Jquery replace> character by html code

I am trying to change the arrow> ( &gt

) breading brackets to "using jquery.

<div id="breadcrumbs"> <a title="Go to cbc." href="http://cbcsales.co.il/newsite" class="home">Home</a> &gt; testpage</div>

I have tried using the following jquery. But the tag is missing. It replaces the character <a>

tag >

. Help me. Thanks to

jQuery("#breadcrumbs").text(function(index, text) {
    return text.replace('>', 'ยป');
    });

      

+3


source to share


5 answers


Just call replace

on the element itself, not inside the function:

Demo



jQuery("#breadcrumbs").html(
    jQuery("#breadcrumbs").html().replace('&gt;', 'ยป')
);
      

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="breadcrumbs"> 
    <a title="Go to cbc." href="http://cbcsales.co.il/newsite" class="home">Home</a>
    &gt; testpage
</div>
      

Run codeHide result


+3


source


Use .html () in .text () like this



jQuery("#breadcrumbs").html(jQuery("#breadcrumbs").html().replace("&gt;", "&raquo;"));

      

+2


source


Your function was almost right, but you had to replace >

with &gt;

which one you wrote and .text

for .html

:

jQuery("#breadcrumbs").html(function(index, html) {
    return html.replace(/&gt;/g, 'ยป');
});

      

Fiddle

0


source


var s = 'some+multi+word+string'.replace(/\+/g, ' ');

      

0


source


Try to change the attribute #breadcrumbs

inside JQuery with .home

. You will see that the link is still there.

Fiddle

0


source







All Articles