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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:28:54+00:00 2026-06-08T02:28:54+00:00

I am utilizing jquery to populated some divs with images. When I click on

  • 0

I am utilizing jquery to populated some divs with images. When I click on a jstree node, the divs should populate. It works but sometimes my calls to images are coming back empty eventhough there are images in the directory.

Here is a piece of code that shows what I am doing:

}).bind("select_node.jstree", function (event, data) {

var ImgTeamA;
ImgTeamA = "img/"+node_id+"-teamA.png";
myImg1 = new Image;
myImg1.src=ImgTeamA

alert(myImg1.width);
alert(myImg1.src)

$("#div1").html(myImg1).css("border","1px solid");

The problem is this. Eventhough myImg1 exists in img directory, alert(myImg1.width) sometimes shows is as 0. When I click on the node again, div1 shows the image. It is sporadic. Sometimes single click shows the image, sometimes I have to double click the node. Can anybody give me some pointers how to tackle this problem.

  • 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-08T02:28:55+00:00Added an answer on June 8, 2026 at 2:28 am

    You can’t get the width of the image before it’s loaded in the browser, try something like:

    }).bind("select_node.jstree", function (event, data) {
        var myImg1 = new Image;
            myImg1.src = "img/"+node_id+"-teamA.png";
            myImg1.onload = function() {
                alert(myImg1.width);
                alert(myImg1.src);
            }
    
        $("#div1").html(myImg1).css("border","1px solid");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a great stand-alone web form in asp.net utilizing many jQuery features
The debug build of some code utilizing SFHFKeychainUtils that is working without complaint on
Using the jQuery cycle plugin: jquery.cycle.all.min.js - latest version (2.8.8) from http://malsup.com/jquery/cycle/ I'm utilizing
I'm writing a system utilizing jQuery Validation that pulls in custom rules, messages via
I have a page that is currently utilizing a jQuery plug-in for truncating text
I am relatively new to jQuery but the below code seems logical but is
I am developing a website utilizing PHP, MYSQL and jquery. In one particular form,
I'm building an app utilizing JQuery Mobile in which I'm showing a progress bar
I am building an app utilizing jQuery UI draggable/droppable. I need to drag boxes
I've set up a page to load data via AJAX, utilizing the jQuery .load

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.