Reputation: 6276
I'm fetching img src attribute into a variable, while doing so I'm getting the complete url of the image, i want to remove domain name from the url
var imgurl = "http://nitseditor.dev/img/home/bg.jpg";
I want to have only img/home/bg.jpg
. How can I achieve it?
Upvotes: 7
Views: 8537
Reputation: 115222
Get substring by getting the index of third /
.
var imgurl = "http://nitseditor.dev/img/home/bg.jpg";
console.log(
imgurl.substr(imgurl.indexOf('/', 7) + 1)
);
Upvotes: 5