444 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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

451 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+6 more
webinpixels says

try this:

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

good luck ;)

444 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+3 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
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Located in Belgium
+4 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
  • Has been part of the Envato Community for over 5 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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 :)

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by