3

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('>', '»');
    });
1
  • 1
    Why are you trying to replace a tag when it is clearly text? text.replace('&gt;', '»')? Commented Dec 20, 2014 at 13:43

5 Answers 5

4

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>

Sign up to request clarification or add additional context in comments.

6 Comments

@putvande well spotted, fixed.
Thanks for reply. But home link is missing.
@user3575182 see my updated answer. You need to use html() instead of text().
Ohh there is a problem. It is replacing in only one &gt; second one is not changing.
@user3575182 there is only one in your question.
|
2

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

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

Comments

0

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

Comments

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

Comments

0

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

Fiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.