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 9190673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:31:00+00:00 2026-06-17T20:31:00+00:00

With the following function I can apply the img width to its surrounding div:

  • 0

With the following function I can apply the img width to its surrounding div:

$(document).ready(function(){

  $('.imagecontainer').each(function() {
    $(this).width( $(this).find('img').attr('width') );
  });

});

The problem is that this only works, when the img has a width attribute. How can I add the img width to the surrounding .imagecontainer div, even when the img tag doesnt have a width attribute? I can display the image width with the load() function, but have no glue how to apply it to the divs width.

  • 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-17T20:31:01+00:00Added an answer on June 17, 2026 at 8:31 pm

    using attr gives the attribute value and if not defined it would not work. You can use

       $(this).width = $(this).find('img').width;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can someone help with this? I need the following function to do this... $x
I am new to jQuery. I have the following code: jQuery(document).ready(function() { jQuery('#carousel').jcarousel(); });
Is it possible to write a Hadoop-ready reduce function that can find the longest
I know the following function can be used to do some pre-save processing. But,
How can the following function be implemented in various languages? Calculate the (x,y) point
Let's consider the following scenario: a function which can generate code colors from white
I have the following function - it works fine in Firefox: How I can
Can anyone describe the following php function: function get_setting_value($settings_array, $setting_name, $default_value = ) {
In the following jquery function, can someone explain to me why second is being
I would like to know if I can use the following JQuery function on

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.