How to get width of an image after setting the height


Tags: jquery,html,css,width

Problem :

I have set the height of my images to 100px (in css). The width is automated to keep the images in proportion but how do I get the width with jquery/js if I haven't specifically set it my self?

This is what I have tryed:

1) $(this).width();

2) $(this).css("width");

Both not working, any ideas?



Solution :

Try using this:

$(window).on('load', function() {
var x = 0;
$("img").each(function () {
x += $(this).width();
});
    alert(x);
});

Fiddle: http://jsfiddle.net/KFhG8/


    CSS Howto..

    CSS issue - How to Prevent Floating Objects from Wrapping in a Container, without changing size of container?

    simplecart.js Images not Showing in IE8 on blogger.com site

    How can I set the main theme-font dynamically, in WordPress

    How to get this image border effect with CSS [closed]

    How to add your customise arrows in slick slider JS using CSS

    How to manage css of big websites within team environment without mess?

    How to center an image over another image in CSS

    How can I make an unclickable HTML “Ghost” Div?

    How to skew element but keep text normal (unskewed)

    Creating “columns” inside a DIV: how to place them?

    How can div with be controlled with responsiveness

    How to add padding to the cells of a table with CSS [closed]

    How to use Sass mixin transition for applying transition-delay only?

    How to align Navbar at bottom of window, but have content under this in CSS?

    How to set style for a column in an extjs 4 grid [closed]

    How to create a WordPress theme that use BootStrap?

    how to append an icon to an input search?

    CSS :hover that shows more than one image

    HOW to combine two element that has different parent in CSS? [duplicate]

    How do I draw a line in CSS that starts wide and ends in a point [duplicate]

    How to find the css file name associated with an element?

    how do I override user agent — using buttons from angularjs

    Give a box an ID, once clicked shows alert of that ID?

    How to arrange three flex div side by side

    How do I override * asterisk for css?

    how to get background image present in other folder with css?

    How can I show an attribute as text with CSS?

    How can I add value to textbox, instead of setting value

    How can I show a loading screen while a really large image is loading?

    how to create 100% vertical line in css