Looking to find a way to remove a part of the url and then put it all back together.
For example if site is https://example.com/ko/xxx/xxxx
I want to remove the ‘ko’ and it be https://example.com/xxx/xxxx
I also think I need to loop through the items as it’s checking if the link has the classname `int-tooltip’
var ko_link_url = $(".int-tooltip");
var ko_link_url_href = ko_link_url.attr("href");
var split = ko_link_url_href.split("/");
ko_link_url_href = ko_link_url_href.split("/");
ko_link_url_href = ko_link_url_href[3];
if (ko_link_url_href == "ko") {
ko_link_url_href.replace(split[3], "");
}
3
Answers
I think you’re making this a bit more complicated than it needs to be – just search for
https://example.com/ko/
and replace withhttps://example.com/
. Loop through elements with.each
.If I understand you correctly, you want to find all the anchors with class
int-tooltip
andhref
starting withhttps://example.com/ko/
and remove theko
part.Consider the following.
This splits the URL into an array, based on the
/
character. You can then iterate each part of the array and check the value. If it is found, you can use.splice()
to remove it from the array. You can join the parts back with/
character.