1

I want to edit src attribute of all my images. I actually want to remove remove "\test" from all the images src. I have tried replace and src.replace in jquery, but it didn't work out can. Please help how to do that.

$("img").each(function(){
            var srcVar = this.attr('src');
            this.attr('src', "http://www.abc.gr"+srcVar);
        });
1
  • +srcVar.split("/test")[1] Commented Jan 12, 2013 at 13:48

3 Answers 3

1

Try this out...

$("img").each(function(){
    var srcVar = $(this).attr('src');
    srcVar = srcVar.replace("/test", "");
    $(this).attr('src', srcVar);
});
Sign up to request clarification or add additional context in comments.

Comments

1

This should help you:

$("img").each(function(){

    // get the current source, replace the test string
    var srcVar = this.attr('src').replace('/test', '');

    // apply it back
    $(this).attr('src', srcVar);
});

Comments

0

Use $(this) instead:

$("img").each(function(){
    var srcVar = $(this).attr('src').replace("/test", "");;
    $(this).attr('src', srcVar);
});

Comments

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.