-1
<div class="breadcrumbs">
    <a href="http://domain.com/dev/topics/pagename" class="category">Test</a>
</div>

I have the above domain and which is I would like to remove the topics/ part, I have tried the below piece of javascript but it always returns the url from the above example.

var breadcrumbURL = jQuery('.breadcrumbs .category').attr('href');
breadcrumbURL.replace("topics/", "");
console.log(breadcrumbURL);
jQuery('.breadcrumbs .category').attr('href',breadcrumbURL);
ngplayground
  • 20,365
  • 36
  • 94
  • 173

3 Answers3

3

This doesn't change breadcrumbURL:

breadcrumbURL.replace("topics/", "");

it returns the string with the replaced text. To update the original, say:

breadcrumbURL = breadcrumbURL.replace("topics/", "");
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
1

You're not assigning the result of the replace to anything.

Change...

breadcrumbURL.replace("topics/", "");

To...

breadcrumbURL = breadcrumbURL.replace("topics/", "");
freefaller
  • 19,368
  • 7
  • 57
  • 87
0

replace your line 2 by :

breadcrumbURL = breadcrumbURL.replace("topics/", "");

http://www.w3schools.com/jsref/jsref_replace.asp

BastienSander
  • 1,718
  • 4
  • 24
  • 50