jquery: image width on domready or load?
问题 hey guys, I'm using the jquery data() method to store the width of images. When is jquery able to get the width of images. on-dom-ready or on-load? Is it necessary to have the images loaded to query it's width, or can i query the width on domready as well? thank you this is my piece of code: //Save the original image width $(".post-body img").each(function() { $(this).data('width', $(this).width()); }); 回答1: It depends, if you're specifying the width, then DOM ready works fine. If you're