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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:44:17+00:00 2026-06-18T10:44:17+00:00

Simple code: $(document).ready(function(){ console.log($(‘.slide-background’).width()); }); and simple html: <div class=testdiv> <img class=slide-background src=img/slide.png/> </div>

  • 0

Simple code:

$(document).ready(function(){
    console.log($('.slide-background').width());
});

and simple html:

<div class="testdiv">
      <img class="slide-background" src="img/slide.png"/>
</div>

As well as simple CSS:

        body {
            margin: 0; padding: 0;
            height: 100%; width: 100%;
        }

        html {
            margin: 0; padding: 0;
            height: 100%; width: 100%;
        }   
        .testdiv {

            overflow: hidden;
            width: 100%; 
            height: 100%; 
            background-color: black;
        }

Why on earth does it output the width whenever it wants? Sometimes the width actually gets logged, however most of the time a 0 is returned.

  • 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-18T10:44:19+00:00Added an answer on June 18, 2026 at 10:44 am

    In jQuery $(document).ready() runs code when the DOM is loaded (which does not include images), $(window).load() runs code when everything is loaded.

    Simply put, the image width is 0 because it hasn’t loaded at the point your code is running.

    Use $(window).load() instead.

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

Sidebar

Related Questions

I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},
I am testing this simple code below and it works... $(document).ready( function() { $('.show-modal').click(
<script> $(document).ready(function(){ <?php echo 'var timeLeft = 12796;'; ?>; console.log(timeLeft); }); </script> How is
I have a simple color animation with jquery.color . This is my code: $(document).ready(function(){
Pretty simple code: html: <div id=wrap style=background-color:gray; height:2000px;> </div> js: <script type=text/javascript> $(document).ready(function(){ $(document).on('mouseup',
<script type=text/javascript> $(document).ready(function($){ $.supersized({ //Background image slides : [ { image : 'images/pendulumWeb.jpg' }
I'm, making a simple AJAX call on page load... $(document).ready(function() { $.get('', {'format': 'json'},
With this code we can create a simple word document but I need to
Simple code indeed : int number = int.MaxValue; number = number+1; Console.WriteLine(number); Questions :
The simple code block below can be served up in a static HTML page

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.