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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:01:26+00:00 2026-05-23T13:01:26+00:00

The Following code determines the sources of two images within an HTML5 Canvas: var

  • 0

The Following code determines the sources of two images within an HTML5 Canvas:

var sources = {
darthVader: “darth-vader.jpg”,
yoda: “yoda.jpg”
};

Is there a way I can change the source of these images using jquery?

  • 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-23T13:01:27+00:00Added an answer on May 23, 2026 at 1:01 pm

    I think @robertc has what you are after, alternatively if your images are stored elsewhere and you want to update the canvas based on an event (e.g. a link/image click) you would need to do something similar to the following;

     <canvas id="e" width="177" height="113"></canvas>
     <script src="jquery.js"></script>
     <script>
    // This originally sets the canvas up with image.jpg
      var canvas = $("#e")[0]; // only get first one
      var context = canvas.getContext("2d");
      var img = new Image();
      img.src = "image.jpg";
      img.onload = function() {
      context.drawImage(img, 0, 0);
      };
      </script>
      <a id="a">click</a>
    
       <script>
       $('#a').click(function(){
       var canvas = $('#e')[0];
       canvas.width = canvas.width;//blanks the canvas
       var c = canvas.getContext("2d");
        var img = new Image();
        img.src = 'image2.jpg';
       img.onload = function(){
        c.drawImage(img, 0, 0);
       }
       return false;
      });
      </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to determine the intersection of two 2D lines. It's
I have the following code to determine the unix timestamp of midnight tomorrow. It
I am using the following code to determine if I can write to a
With CLLocationManager I can use the following code to determine if I can access
I'm trying to determine the width of a string. I'm using the following code
Following code iterates through many data-rows, calcs some score per row and then sorts
following code doesn't work with input: 2 7 add Elly 0888424242 add Elly 0883666666
Following code is from a sample of playframework-2.0: /** * Display the dashboard. */
Following code is to save image took from camera into photo album. if ([mediaType
The following code works fine: person = {:a=>:A, :b=>:B, :c=>:C} berson = {:a=>:A1, :b=>:B1,

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.