Im not sure how I can achieve this or if its even possible but im trying to change one word in my url using jquery, my url is bring used multiple times with different sub directories this is what I have so far.
as you can see im trying to replace the word collections with albums
(function($) {
var thePage = $("body");
thePage.html(thePage.html().replace(/collections/ig, '<a href="http://mysite.com/collections/12/College-Life/most_recent/all_time/">blah blah</a>'));
})(albums)
im not sure what to do, i happened to stumble across a site giving a little bit of detail on what to do but it wasnt much
I suspect part of your problem is that you are passing
albumsas the$identifier for jQuery and that is probably not correct.If what you’re trying to do is to replace the word “collections” everywhere in your HTML page with a linkified version of that word, then you can use this simplified version of the code (no need to use jQuery in places it isn’t helpful):
I should warn you that this simple replacement will also affect occurrences of “collections” that might be in URLs in the HTML page too, not just text in the page.
If what you’re trying to do is to change a word in the actual URL of the page, then that would take a different block of code to operate on
window.location.href.Based on the new information in your comment, it sounds like you’re trying to change the word “collections” in all URLs in the document to “albums”. To do that, you would use code like this:
This gets all the links in the document, cycles through them and replaces any occurrence of “/collections/” in the click destination for that link with “/albums/”.