Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8846031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:52:38+00:00 2026-06-14T11:52:38+00:00

This code: $(‘#ad img’).each(function(){ if($(this).width() > 125){ $(this).height(‘auto’); $(this).width(125); } }); is working properly

  • 0

This code:

$('#ad img').each(function(){
    if($(this).width() > 125){
        $(this).height('auto');
        $(this).width(125);
    }
});

is working properly on Firefox but not Chrome. The img tags inside of #ad are constricted by height, but if this makes them too wide I need to restrain the width. Is there a better way to do this that would work on all browsers?

The html for the image is as follows:

<img src='http://easyuniv.com/img/ads/".$ad['img']."' height='40px'>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:52:39+00:00Added an answer on June 14, 2026 at 11:52 am

    I suspect what is biting you is the variability in image load. If the image itself hasn’t loaded by the time your code runs, it will have width of 0. You might want to try using a load handler as well as running your existing code to ensure that the images are sized properly. Note: you’ll need to use your existing code to handle the case where the image is loaded before the load handler is added.

    $(function() {
        $('#ad img').on('load', function() {
              resize(this);
        }).each( function() {
              resize(this);
        });
    
        function resize(image) {
           var $image = $(image);
           if ($image.width() > 125) {
               $image.css( { height: 'auto', width: 125 } );
           }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this code run firefox , but error on ie why ? please help me.
This code works fine in <= IE7, but it doesn't work in firefox ..
This code works properly in my localhost. I am using xampp 1.7.3. but when
This code disabled mouse scroll functionality, when i click on the document. $(document).on(click, function
This code : http://jsfiddle.net/bYtTG/1/ Works as I want in FF, chrome and opera, but
This code is not pretty, but I want to print out the last generated
This code all works, but I'm basically blundering around my lack of knowledge in
This code below works fine in Chrome and IE 9. But breaks in IE
This code $(document).ready(function(){ $(.one).hover( function(){ $(.overlay).fadeTo(200,1).show(); }, function(){ $(.overlay).delay(500).fadeTo(200,0); } ); }); overlays a
This code doesn't work what's wrong? $(.re).focus(function() { if($(this).attr(type) == text) { $(this).attr(type, password);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.