-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
  • 18,559
  • 34
  • 93
  • 168

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
  • 35,848
  • 27
  • 79
  • 88
1

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

Change...

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

To...

breadcrumbURL = breadcrumbURL.replace("topics/", "");
freefaller
  • 18,589
  • 7
  • 54
  • 82
0

replace your line 2 by :

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

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

BastienSander
  • 1,605
  • 4
  • 22
  • 41