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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:36:39+00:00 2026-06-04T05:36:39+00:00

I have a long base64 type string I get and I’d like to set

  • 0

I have a long base64 type string I get and I’d like to set as the src of the image

 $('#img').attr('src',base64data)
 console.log('height - ' $('#img').height());
 console.log('width - ' $('#img').height());

It looks like im getting back 0 for both height and width. Of course if I wait a while
then i’ll get the proper height.

The thing is .attr() doesn’t have a callback, how would I get about getting the height and width after the src attribute is set without getting 0 back. (I think i’m getting 0 because the change in Jquery is happening asynchronously but I cant be too sure)

  • 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-04T05:36:40+00:00Added an answer on June 4, 2026 at 5:36 am
    $('#img').one('load', function() {
       console.log('height - ' $(this).height());
       console.log('width - ' $(this).width());
    })
    .attr('src',base64data);
    
    /* if this image is already cached load event couldn't be fired:
     * then look for "complete" status and trigger load event 
     */
    if ($('#img').get(0).complete) {
       $('#img').trigger('load');
    }
    

    Before getting width and height you need to wait the load event.
    Note that I used one() method, because if the image is already cached it should not fire the load event twice

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

Sidebar

Related Questions

I have my canvas represented as a base64 string. I would like to pass
I have a long string resulted from encoding a binary file -an image file-
I have a textbox to display a very long Base64 string. The TextBox.Multline =
I have a big string (a base64 encoded image) and it is 1050 characters
I have a verrrrrrrry long base64 encoded string which is displayed in a textarea.
I have a long function, as seen below: hash_correct = hashlib.md5(salt + password)).digest().encode(base64) I'd
How long have the MySQL XML functions like ExtractValue() and UpdateXML() been supported? A
I have long text . And I'm converting this string to dict. Here is
How do you handle user stories/acceptance tests that have long chains like this one,
Ok so I have a string of text, encoded in Base 64 like below:

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.