2

please tell me how to get image size of all images in the page using jquery or javascript

2

3 Answers 3

4

The only size you can get is the visible size. clientWidth and clientHeight are two DOM properties which do this. Example:

var image = document.getElementById("id");
var width = image.clientWidth;
var height = image.clientHeight;

If you're using jQuery, you can simply use $.width and $.height:

var width = $("id").width();
var height = $("id").height();

So, to get the size of all images, loop them through:

$("img").each(function()
{
    console.log(this.width());
    console.log(this.height());
});

If you need the real size, please see this question Get the real width and height of an image with JavaScript? (in Safari/Chrome)

Sign up to request clarification or add additional context in comments.

3 Comments

I have a form to upload an image, is there any way to get image dimensions on the client side before I process it on server side.
@SIFE Yes, it is possible in newer browsers. Please ask this in a new question.
See my question pls. stackoverflow must star thinking on url shortening service.
2
$('img').each(function() {
   $(this).width(); // current image's width
   $(this).height(); // current image's height
});

Comments

1

please tell me how to get image size of all images in the page using jquery or javascript

You can use width() and height() method of jQuery:

$('img').each(function(){
   alert('width=' + $(this).width() + '\nHeight=' + $(this).height());
});

More Info:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.