sameeuor
sameeuor

Reputation: 684

jquery replace > character on html code

I'm tring to change breadcrumbs arrow > (&gt) 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 tried using following jquery. But tag is missing. It is replace <a> tag > character. Help me. Thanks

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

Upvotes: 3

Views: 4684

Answers (5)

Hussain Hamdani
Hussain Hamdani

Reputation: 64

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

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

Upvotes: 2

James Donnelly
James Donnelly

Reputation: 128791

Just call replace on the element itself, not within a 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>

Upvotes: 4

Bill
Bill

Reputation: 162

Try to change the #breadcrumbs attribute inside the Jquery with the .home. You will see that the link is still there.

Fiddle

Upvotes: 0

Coder
Coder

Reputation: 240

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

Upvotes: 0

putvande
putvande

Reputation: 15213

Your function was almost right, but you had to replace > with the &gt; you've had written and .text for .html:

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

Fiddle

Upvotes: 0

Related Questions