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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:07:12+00:00 2026-05-15T06:07:12+00:00

i have this code running to load my images all asynch and show a

  • 0

i have this code running to load my images all asynch and show a ajax loading image until the real image is downloaded.

 $('img.loadable-image').css('background', 'transparent url(/images/ajax-loader1.gif) no-repeat center center')
$('img.loadable-image').load(function() { $(this).css('background', ''); });

this works in that it shows my ajax loading icon until the images is downloaded but it also shows the background as well

here is my original image html:

<img class="loadable-image" src="mysite.com/validimage.jpg" border="0" height="50" width="50">

here is a screenshot of what i get:

alt text http://img820.imageshack.us/img820/3289/ajaxload.png

as you can see on the left, you see the little ajax loader but also see the missing image square around it.

any suggestions?

  • 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-15T06:07:12+00:00Added an answer on May 15, 2026 at 6:07 am

    See http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.2, which defines that an <img> tag must have the src attribute.

    The missing square will be due the src attribute of the <img> tag. If it’s not set to a valid image URL, you’ll get the “broken image” frame. Set the src instead of the background (or set it to a transparent image) or change it to a <span> element instead of an <img> element.

    Not valid, no src attribute == “broken image” icon:

    <img alt="" style="width:50px; height:50px; background-image:url(bg.gif)" />
    

    valid, with src attribute:

    <img alt="" src="transparent.gif" 
         style="width:50px; height:50px; background-image:url(bg.gif)" />
    

    After your edit, I can see you’re doing it correctly, the problem is the image taking a long time to download. In that case, you have a few options:

    • If you have control over the images, make them load progressively (save GIF/PNG as interlaced, JPEG as progressive).
    • If you don’t have control over the images, wrap the img hidden in a span, apply the background image to the span element and show the image when the load event fires.

    Ex:

    <span class="loadable-image-container">
        <img class="loadable-image" src="mysite.com/validimage.jpg" 
            border="0" height="50" width="50">
    </span>
    

    jQuery, something like:

    $('img.loadable-image-container')
        .css('background', 
          'transparent url(/images/ajax-loader1.gif) no-repeat center center')
        .children().css('visibility', 'hidden');
    
    $('img.loadable-image').load(function() { 
        $(this)
            .css('visibility', 'visible')
            .parent().css('background', ''); 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code is not running on .click when I have this: $(.cancel).click(function() { alert(got here);
I'm a beginner with jdbc ... I have a problem running this code :
Following the directions at this question , I have some code running to extract
I have this code that performs an ajax call and loads the results into
I have this code in jQuery, that I want to reimplement with the prototype
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this code: CCalcArchive::CCalcArchive() : m_calcMap() { } m_calcMap is defined as this:
I have this code: myVariable which I want to change into trace(myVariable: + myVariable);
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row

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.