How can I get width and height of big image after displaying it on html-page?

Tags: javascript,jquery,html,css

Problem :

I have a big image, in example 10000x8000px. In this case I reduce width and height of image using CSS class .myClass { max-width: 90vw; max-height: 80vh; } How can I get width and height of this image after displaying it on html-page. In example, if I have 1200x800 monitor I want to get result 960x640px using $(img).width() or $(img).height(). Is it possible? When I use $(img).width() or $(img).height() a get natural size 10000x8000px. And img.clientWidth return 0.

Solution :

What I understand is that you want to reduce size of image if it is too big. Assume div.image is an image in the code below and check the code. Use this code to get desired result what you want..

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

if(width > 900) {
	var newWidth = (width * 80) / 100; // reduce to 80% width
  $(".image").css("width", newWidth);

if(height > 900) {
	var newHeight = (height * 80) / 100; // reduce to 80% width
  	$(".image").css("height", newHeight);
  width: 1000px;
  height: 1000px;
  background-color: blue;
<script src=""></script>
<div class="image">

    CSS Howto..

    How to make div height fit the content using css

    css: Image is on the border of parent's div. How to make text above that image in a div?

    How to assign speed parameter to callback functions

    How to reference embedded images from CSS?

    Show/Hide Html TR/TD

    How to use bootstrap to hide one of div when zoom browser windows size smaller

    How is margin-top and margin-bottom getting added

    How to align image to the right?

    how to set a path to the static files which is surver independnet

    Using jquery/JS/CSS how do I append words to a sentence so the sentence is pushed up word by word

    jQuery - How to aply custom CSS to fields which are not empty

    How to put all Array values in $_GET[]

    How to wrap a DIV around a DIV with CSS

    How i can set the height of black overlay in css that all other things goes hidden?

    How to Keep CSS Background Image on top of all divs(breadcrumb arrows)?

    CSHTML - How to I make the unordered list items horizontal?

    how to set menu to activate always hover effect on [closed]

    How to add multiple font files for the same font?

    How to style every odd p element after h2 element occured in css?

    How to make this working Java-script more efficient

    How to same element with unique XPath/CSS selector by both ID and Class?

    HTML5 / CSS| How do I disable responsivity when a scroll bar appears?

    How to programmatically ungroup CSS selectors?

    HTML+CSS: How to add arrow to horizontal menu items?

    how is Zurb's Foundation Menu button coded?

    How can I use jQuery to hide or show table rows based on role?

    CSS: How to get rid of the extra space of first line of a paragraph?

    How we can add a span to a text inside ul, that is outside of li in jquery or css

    How to put logo on navigation bar

    How to scale down retina image sprite with css