I tried with something like this:
var Height = $(this).naturalHeight;
But it doesn't work. Is there any way to do that
greez
var imageWidth = $(Imgsize). width(); alert(imageWidth);
The naturalWidth property returns the original width of an image. For example, if you have an image that is originally 100 pixels wide. Then, you style the image with CSS/or by using the HTML "width" attribute to make it 500 pixels wide.
Answer: Use the JavaScript clientWidth property You can simply use the JavaScript clientWidth property to get the current width and height of an image. This property will round the value to an integer.
I use the native javascript properties after applying jQuery and then stripping jQuery
.naturalWidth / .naturalHeight
On a jQuery object i use
var width = this.naturalWidth; var height = this.naturalHeight;
or
var width = $("selector").get(0).naturalWidth; var height = $("selector").get(0).naturalHeight;
if no jQuery object is selected.
With get(0) on a jQuery object you can access the associated DOM-element. On the native DOM element you can work with native javascript code (here access the nativ javascript attribute .naturalWidth)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With