开发者

loading and replacing the image in jquery

开发者 https://www.devze.com 2023-03-15 02:58 出处:网络
I h开发者_StackOverflowave low resolution image which is loaded first,once it is loaded i need to replace it with a high resolution image.

I h开发者_StackOverflowave low resolution image which is loaded first,once it is loaded i need to replace it with a high resolution image.

I try to do so in html img tag but in throws error saying

Uncaught TypeError: Cannot read property 'width' of undefined


In order to replace the image try using

$('#Image').find('img').attr('src', ['/ImagePath/', NewImageName].join('')); 

Or may be you can consider changing just the src

$('#Image').attr('src', '/ImagePath/NewImageName');


JavaScript only:

document.getElementById('idOfYourImg').src = '/new/path.png';

jQuery:

$('#idOfYourImg').attr('src', '/new/path.png');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号