1

The system I'm using occasionally adds the full path to the src of a dynamic img.

<a href="#" class="link">
    <img src="http://www.domain.com/images/wish-add.png" alt="" />
</a>

I need everything before /images to to be removed.

I need be able to do it without manually referencing the domain. The domain is not always going to be the same.

I can remove parts that are always the same.. Like /images.. but I don't know how to remove anything before /images regardless of what it is.

1 Answer 1

3
$('img').attr('src', function (i, src) {
    return src.replace(/https?:\/\/[^\/]+/, '');
});
Sign up to request clarification or add additional context in comments.

1 Comment

That worked a treat! I'll have to read up - I don't fully understand it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.