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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:08:19+00:00 2026-05-30T08:08:19+00:00

I am a total newbie to JavaScript and jQuery, and need some help. Also

  • 0

I am a total newbie to JavaScript and jQuery, and need some help. Also I apologise if it’s easy and Im just not seeing it!

Basically, I’m trying to find the size of an image after it has loaded, so I can use this information to adjust the width of a div.

This is the code currently:

<script type="text/javascript" src="js/jquery.js"></script>

<img id="Img1" src="01.jpg" style="height: 50%; width: 50%;" />

<script>
$(document).ready(function() {
     $(Img1).load(function() {
       alert($(this).width());
    });
});
</script>

Which creates a prompt box with the correct width! But I cant seem to find a way to reuse this information or declare a variable from it!

Please can anyone help me? Any help would be greatly appreciated! Thanks.

  • 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-30T08:08:21+00:00Added an answer on May 30, 2026 at 8:08 am

    Since Img1 is the id of img element use it as id to select it. To store the value of width you can declare a variable and store in it. And then use the variable wherever required.

    $(document).ready(function() {
        var imgWidth;
        //Selecting image using id selector
        $("#Img1").load(function() {
           imgWidth = $(this).width();
        });
    });
    

    You should learn at various selectors that jQuery offers you to use based on your markup structure. Take a look at this link http://api.jquery.com/category/selectors/

    Note: If you want to use this variable across the page then you should define it in the outer or global scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a total newbie when it comes to Javascript/jQuery so hopefully you can help
I'm a total newbie and want to start with php. I know some javascript
I'm a total newbie on BIRT and I'm not a javascript pro. I am
I am not a total newbie but I am trying to install modules for
Total newbie question but this is driving me mad! I'm trying this: myInt =
This is a total newbie question, so thanks in advance. I'm trying to get
I am a total newbie in servers/hosting etc, although I have some experience in
I know this is a total newbie question, but the answer may not be
I'm a total newbie regarding to DLL. And I don't need to creat them
I'm just starting out with Lithium, and I'm a total framework newbie, so I'm

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.