444 posts
  • 5 Years of Membership
  • Collector Level 1
  • Exclusive Author
  • United Kingdom
TahaH-Studio
says
$(document).ready(function(){
    $("img").each(function(){ 
        var newImgWidth = $(this).width() - 6;
        $(this).width(newImgWidth);
    });
});

Hey guys, I wrote the above code to resize any image on my website by 6px. Its working fine in ff, IE but not in Chrome or Safari (webkit). Any ideas why its not working?

Thanks

461 posts Don't be a HATER!
  • Weekly Top Seller
  • Elite Author
  • Author Level 8
  • Featured Author
+6 more
CodeElite
says

try this:

$(document).ready(function(){
    $("img").each(function(){ 
        var newImgWidth = $(this).width();
        $(this).css('width', parseFloat(newImgWidth - 6) + 'px');
    });
});

good luck ;)

444 posts
  • 5 Years of Membership
  • Collector Level 1
  • Exclusive Author
  • United Kingdom
TahaH-Studio
says
try this:
$(document).ready(function(){
    $("img").each(function(){ 
        var newImgWidth = $(this).width();
        $(this).css('width', parseFloat(newImgWidth - 6) + 'px');
    });
});
good luck ;)

Still doesn’t work. My code works only when I add the width attribute to the element. Is there anyway (with jguery) to automatically add the width attribute to the element?

73 posts
  • 6 Years of Membership
  • Author Level 2
  • Collector Level 2
  • Exclusive Author
+5 more
illusionem
says

try using your img code in $(window).load(function(){ }); webkit browsers render css and js in parallel this should do it ;)

86 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Author Level 6
  • Belgium
+6 more
BrentChesny
says
try this:
$(document).ready(function(){
    $("img").each(function(){ 
        var newImgWidth = $(this).width();
        $(this).css('width', parseFloat(newImgWidth - 6) + 'px');
    });
});
good luck ;)
Still doesn’t work. My code works only when I add the width attribute to the element. Is there anyway (with jguery) to automatically add the width attribute to the element?
$(document).ready(function(){
    $("img").each(function(){ 
        var newImgWidth = $(this).width();
        $(this).attr('width', parseFloat(newImgWidth - 6));
    });
});
444 posts
  • 5 Years of Membership
  • Collector Level 1
  • Exclusive Author
  • United Kingdom
TahaH-Studio
says
try using your img code in $(window).load(function(){ }); webkit browsers render css and js in parallel this should do it ;)

@abhin2cool, Thanks alot mate. That worked :D, you rock ;)

@BCProducties, I haven’t tried your suggestion but thanks for your reply. I really appreciate it :)

by
by
by
by
by
by