Daniele Brunengo
asked on
Natural height and jquery
Hello, I am quite the jquery newbie and I'm trying to get the height of an image file. I mean the actual height of the image, not as it appears on screen.
So I wanted to use naturalHeight and I did this:
It's inside a function applied to the row containing the image. There is a single image with the vc_single_image-img class.
I used get(0) to "convert" the jQuery object to the standard DOM element. I thought it would work, but I keep getting this error:
I'm clearly missing something big here, as I said I'm a newb. So can somebody help me? Thanks.
So I wanted to use naturalHeight and I did this:
var nath = jQuery('.vc_single_image-img', this).get(0).naturalHeight;
It's inside a function applied to the row containing the image. There is a single image with the vc_single_image-img class.
I used get(0) to "convert" the jQuery object to the standard DOM element. I thought it would work, but I keep getting this error:
TypeError: jQuery(...).get(...)
I'm clearly missing something big here, as I said I'm a newb. So can somebody help me? Thanks.
jQuery returns an array so to get the actual element
Try this
Try this
var nath = jQuery('.vc_single_image-img', this)[0].naturalHeight;
ASKER
@Leonidas, I don't need the height of the element but of the actual file.
Anyway that's not the problem, because I get the same error if I use height. The problem is in the jQuery(...).get(...) syntax, the script doesn't even reach the following command (height or naturalHeight).
@Julian, sorry for not mentioning this, I had already tried that solution. I get the same error.
I also tried with children() and find() but the error is the same.
Anyway that's not the problem, because I get the same error if I use height. The problem is in the jQuery(...).get(...) syntax, the script doesn't even reach the following command (height or naturalHeight).
@Julian, sorry for not mentioning this, I had already tried that solution. I get the same error.
I also tried with children() and find() but the error is the same.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, this works.
You are welcome.
Open in new window
Using the height() function you get the height of the image elementJQuery
Open in new window