0

I'm trying to add some no-cache prefix to images:

var cacheId = Math.floor(Math.random() * 10000) + 1;
$(this).attr('src', src + cacheId);

but i have an error: src is not defined, what is wrong?

3
  • you haven't defined the the variable src Commented Feb 4, 2014 at 13:23
  • i need to add only some sign to src, i don't need variable Commented Feb 4, 2014 at 13:24
  • Try this dummies.com/how-to/computers-software/programming/… Commented Feb 4, 2014 at 13:26

1 Answer 1

1

Your variable named src is is currently undefined.

I believe you want to do something like this. Fiddle.

$(document).ready(function () {  
    $("img").each(function () {
        var src = $(this).attr('src');
        var cacheId = Math.floor(Math.random() * 10000) + 1;
        $(this).attr('src', src + "?r=" + cacheId);
    });
});
Sign up to request clarification or add additional context in comments.

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.