<script type="text/javascript" src="/path/to/jquery.js"></script> <script type="text/javascript"> jQuery.event.add(window, "load", function(){ var fw = 100; //fixed width var fh = 100; //fixed height var sl = 'img.hoge'; //selector $(sl).each(function(){ var w = $(this).width(); var h = $(this).height(); if (w >= h) { $(this).width(fw); } else { $(this).height(fh); } }); }); </script> <img src="sa