MrCaps
MrCaps

Reputation: 13

JS replace hashtag with slash

Im wondering how do I replace a hashtag with a slash in the URL with Javascript or Jquery.

Example:

www.mysite.com/service#new

To:

www.mysite.com/service/new

Is this possible? I really can´t figure it out.

Greetings!

Upvotes: 1

Views: 1253

Answers (1)

p.s.w.g
p.s.w.g

Reputation: 149020

Why not just do this:

var url = "www.mysite.com/service#new";
url = url.replace('#', '/');

Or if you're trying to manipulate DOM elements directly, something like this should work:

$('a').each(function(i, e) {
    e.href = e.href.replace('#', '/');
});

Upvotes: 2

Related Questions