0

I'm having a little trouble getting this to work correctly.

I have breadcrumbs with the following structure

<nav class="breadcrumb" >
    <a href="http://example.com">Home</a>       
        ">"         
    <a href="http://example.com/category/Mens/">Mens</a>        
        "> Mens Clothing"       
</nav>

Which outputs to:

Home>Mens>Mens Clothing

I want:

Home>Mens>Clothing

And my code for replacing the last part of the breadcrumb:

$(".breadcrumb").text(function(){
    return $(this).text().replace("Mens Clothing", "Clothing");
})

My problem is that my code removes the links and just leaves me with"

<nav class="breadcrumb" >
    "Home>Mens>clothing"
</nav>

with no links.

Not sure why. Please help

1
  • 2
    Why don't you render it server side instead? If you don't want "> Mens Clothing", why are you in first place setting it? Commented Jun 14, 2015 at 18:17

2 Answers 2

2

Try using html() instead of text():

$(".breadcrumb").html(function(){
    return $(this).html().replace("Mens Clothing", "Clothing");
});
Sign up to request clarification or add additional context in comments.

1 Comment

Bingo! Thanks. I'll look up the difference between the two, though I can already kinda guess. Thanks!!!!
0

With your current HTML, you could change your approach to

<nav class="breadcrumb" >
    <a href="http://example.com">Home</a>       
        ">"         
    <a href="http://example.com/category/Mens/">Mens</a>        
        "> <span data-last-crumb>Mens Clothing</span>"       
</nav>


$("[data-last-crumb]").text("Clothing");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.