Home > DeveloperSection > Forums > Retrieve original image length & height with jquery?
Sanjay Sharma
Sanjay Sharma

Total Post:45

Points:315
Posted on    January-30-2015 10:05 PM

 ASP.Net JQuery  HTML  CSS 
Ratings:


 1 Reply(s)
 630  View(s)
Rate this:

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 working

Any help will be appreciated, thanks.



Ankit Singh

Total Post:341

Points:2389
Posted on    January-30-2015 10:24 PM

$(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 */

        };

    });

});


Don't want to miss updates? Please click the below button!

Follow MindStick