I have a display thumbnail at 250px by 250px. I want to be
able to retrieve its original width and height when clicking on the thumbnail.
I tried doing this:
$(function() {
$(".img_section").on('click',function() {
var img = $(this).children(".test_img").attr("src");
theImg.src =img.attr("src");
var imgNaturalWidth = theImg.width();
var imgNaturalHeight = theImg.height();
alert(imgNaturalWidth);
alert(imgNaturalHeight);
}) // not workingAny help will be appreciated, thanks.
Anonymous User
30-Jan-2015$(function () {$(".img_section").on('click', function () {
$this = $(this).children('img');
var image = new Image();
image.src =$this.attr("src");
image.onload =function () {
alert('width:' + this.width +' '+'height: '+ this.height); /* calculation the width and height from image onload */
};
});
});