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

  • Home
  • SEARCH
  • 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 7025841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:02:01+00:00 2026-05-28T00:02:01+00:00

I am trying to scale images to fit within their parent element width, and

  • 0

I am trying to scale images to fit within their parent element width, and especially for images located in tables.

The problem was that different browsers and platforms seem to behave differently when it comes to determining the width of the parent element.

So I tried to get the width of the parent td element in $(document).ready:

$('td').each(function () {
    var width = $(this).width();
    $(this).width(width);
});

And then in $(window).load (when the images should be loaded) I try to set the width of the images according to the width css style of the td:

var parentWidth = $(this).parent().width();
if ($(this).closest('td')) {
    parentWidth = $(this).closest('td').css('width').replace('px', '');
}

But this seems to be unreliable. It works sometimes, and in some browsers, but sometimes it fails miserably, giving the wrong value for the td width.

I want to be able to get the width of the td before the images are loaded, so that the width isn’t distorted by the images expanding it.

Of course, none of this would have been necessary, if it wasn’t for IE8 and below not supporting max-width and max-height, but it doesn’t.

How can I do this and get the parent widths before images are loaded?

BTW: the td can have a width percentage value to start with in a 100% width table.

  • 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-05-28T00:02:02+00:00Added an answer on May 28, 2026 at 12:02 am

    This line is incorrect:

    if ($(this).closest('td'))
    

    closest returns a jQuery object with 0 or 1 element. You probably mean:

    if ($(this).closest('td').length == 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to scale a bunch of images so that they have the same
Good day all; I am trying to manually (not using sublayers) draw images within
I have a few images I'm trying to normalize to a certain scale by
I'm trying to convert hundreds of images that Have an unknown subject centered in
I'm trying to dynamically scale text to be placed on images of varying but
im trying to make my images fit nicely into screen without overlapping but no
I'm trying to create a scale functionality for certain images when they are hovered,
I'm trying to get every widget to scale with change in window size. I
I am trying to parallelise a code using scala actors. That is my first
I'm trying to grasp higher-order-polymophism in scala by implementing a very basic interface that

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.