-1
<script type="text/javascript">
     $(document).ready(function () {

         $("#aspnetForm img").load(function () {
             $(this).width(64);
             $(this).height(64);
         });
     });
</script>

 <asp:TemplateField>
                <ItemTemplate>
                <img alt="" runat="server" class="pic" style="cursor:pointer" src='<%# StripHTML(Eval("cat_img").ToString()) %>'  />
                </ItemTemplate>
                </asp:TemplateField>

It is working in Chrome, but not on IE. Please help me. My image is <p> <img src=....> html tag in database. I cleared striphtml method.

geffchang
  • 3,279
  • 2
  • 32
  • 58
david5
  • 53
  • 9
  • this links will help you http://stackoverflow.com/questions/3877027/jquery-callback-on-image-load-even-when-the-image-is-cached – sasi Feb 07 '13 at 11:29

4 Answers4

0

Images aren't yet loaded on ready event use $(window).load() instead On ready only the DOM structure is loaded but not the real images. It's like you're having the img tag but not the file yet


OK your problem is totally different, you're looking for this, my mistake You just want to iterate some images and make them 64x64 that should work

$(document).ready(function () {
    $("#aspnetForm img").each(function () {
         $(this).width(64).height(64);
    });
});

or

$(document).ready(function () {
    $("#aspnetForm img").each(function () {
        $(this).css({width:64+'px',height:64+'px'});
    });
});

If you want to get the width of each image you should wait for the img to load

 $(window).load(function () {
     var width, height;
     $("#aspnetForm img").each(function () {
         width = $(this).width();
         height = $(this).height();
         //store the current img width or height or do whatever
     });
 });
kidwon
  • 4,448
  • 5
  • 28
  • 45
  • – david5 Feb 07 '13 at 11:07
  • `$(window).load()` instead of `$(document).ready()` or you can still put it inside `$(document).ready(function(){})` if some closure logic. Just make sure that the logic regarding images size is inside `$(window).load(function(){....})` – kidwon Feb 07 '13 at 11:09
  • replace documen.ready to window.load chore not working too..:( – david5 Feb 07 '13 at 11:14
0

Try this instead:

$(document).ready(function () {
    $("#form img").css({"height":"64px","width":"64px"});
});   

The fiddle: http://jsfiddle.net/devWaleed/6eas3/4/

Joe
  • 15,205
  • 8
  • 49
  • 56
devWaleed
  • 475
  • 3
  • 14
0

Don't use .load(), it's deprecated.

Try this, should work for all browsers:

$(document).ready(function() {
    $('#aspnetForm img').css('width', '64px')
                        .css('height', '64px');
});
evilReiko
  • 19,501
  • 24
  • 86
  • 102
0

Try with this:

Reference:http://api.jquery.com/load-event/

$(document).ready(function() {
    $("#aspnetForm img").load(function() {
        alert($(this).height());
        alert($(this).width());
    });
});

Here is another way to do this: DEMO

function imageSize(img){
   var theImage = new Image();
   theImage.src = img.attr('src');
   var imgwidth = $(img).width();
   var imgheight = $(img).height();

   alert(imgwidth);
   alert(imgheight);
}

$('img').each(function(){
    var imgsrc = jQuery(this);
    imageSize(imgsrc);
});
coder
  • 13,002
  • 31
  • 112
  • 214
  • That `load` event img bind won't work in some browsers like some versions of Opera 11,12 for instance. Also what happens if the images are a few – kidwon Feb 07 '13 at 11:43