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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:23:58+00:00 2026-05-29T22:23:58+00:00

Say I have the canvas tag in my HTML5 document <canvas id=fooBar width=500 height=200></canvas>

  • 0

Say I have the canvas tag in my HTML5 document

<canvas id="fooBar" width="500" height="200"></canvas>

And I also have an empty anchor tag

<a href="" id="spin">Spin</a>

and I build my canvas in the head

var fooCanvas = document.getElementById("fooBar");
var barContext = fooCanvas.getContext("2d");

Is there a way I can add:

barContext.fillText("fubar", x,y);

Dynamically via clicking on the anchor tag? What I want is to have a variable in my JS which doesn’t always hold the same value, and clicking the a tag would update the canvas fillText attribute every time the link is clicked, My idea to overcome this is to use jQuery and have something like this:

    $(document).ready(function(){
        $("a").click(function(event){
            // Something here
        });
    }); 

Obviously this would work on every a tag I have in the document so I’ll specify that later on but I’m not too sure on the syntax required to append that canvas attribute to my canvas? Any ideas?

  • 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-29T22:23:59+00:00Added an answer on May 29, 2026 at 10:23 pm

    Yes:

    var fooCanvas = document.getElementById("fooBar");
    var barContext = fooCanvas.getContext("2d");
    
    $(document).ready(function(){
        $("a").click(function(event){
            barContext.fillText("fubar", x,y);
        });
    });
    

    Although you might want to use button elements instead of a, since they’re not actually links.

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

Sidebar

Related Questions

Let's say I have a canvas with a fixed height and a vertical scroll
I'm working with the HTML5 canvas element. Let's say I have 2 ImageData objects
Let say I have x, y, width and height. I need to draw a
let's say I have var myCanvas = document.createElement('canvas'); and I do myCanvas.setAttribute(id, my-canvas); document.body.appendChild(myCanvas);
Is it possible to spread an image inside html5 canvas.. like say I have
Say I have objects within the Canvas with a tags 'stopped' and 'flying' .
Let's say I have such PoC code snippet for working with canvas raw pixel
I have a custom class say 'MyCanvas' derived from wpf Canvas class. MyCanvas has
I have a specific sized canvas (let's say 400x300 pixels) and I have an
Lets say we have a 400x800 canvas and I want to draw a line

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.