jquery access image width -- why is this not working?
I am somewhat new to Jquery but I feel complete failure here at not being able to do this. I'm sure its something stupid but I have been at this for far too long.
So if I have html as such...
<div class="lightbox-image">
<img src="http://staging.greencupboards.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/feeds/MrsMeyers/MRM-64558.jpg" />
</div>
Why does this in my Jquery file generate a 'null' in the alert box?
alert($('.lightbox-image img'));
Shouldn't the alert box have something in it such as 'object'?
I have been on Jsfiddle and it still doesn't work. I know I am missing something stupid so I apolog开发者_如何学JAVAize in advance for my naivety. Thanks a lot!
- Nate
EDIT:
alert($('.lightboximage img'));
alert($('.lightboximage img').width());
$('.lightboximage img').load(function() {
alert( $(this).width() );
});
This code generates an object on the first alert and a 0 on the next two alerts. Why is this? I know the image exists and JSfiddle says that its width is 825...
$('.lightboximage img').width(100);
This works for me... I did notice that your image wasnt properly being retrieved from the server (401)
http://jsfiddle.net/uuuwU/
Seems to work for me, I have updated citizen conn script to output the width on the page, looks all good:
http://jsfiddle.net/uuuwU/3/
精彩评论