Month: April 2014

Jquery img src change on screen width/resize

Here is a quick example. http://jsfiddle.net/9v7ad/1/ <html> <img id=”my-img” src=””> </html> <script> $(document).ready(function(){ if($(window).width() < 640 ) { $(‘#my-img’).attr(‘src’,’http://www.24k.com.sg/images/uploads/hosting.jpg’); } if($(window).width() > 640 ) { $(‘#my-img’).attr(‘src’,’http://www.cadac.com/organice/Style%20Library/Images/organice/mainimg/mi-sol-hosted.jpg’); } }); $(window).resize(function() { if($(window).width() < 640 ) { $(‘#my-img’).attr(‘src’,’http://www.24k.com.sg/images/uploads/hosting.jpg’); } if($(window).width() > 640 ) { $(‘#my-img’).attr(‘src’,’http://www.cadac.com/organice/Style%20Library/Images/organice/mainimg/mi-sol-hosted.jpg’); } }); </script> Please follow and like us: