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?
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?
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);
});
});