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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:51:41+00:00 2026-05-26T21:51:41+00:00

I have a HTML5 canvas with a several line segments on it. I want

  • 0

I have a HTML5 canvas with a several line segments on it. I want to add a jQuery color picker so I can let users change the stroke color of those segments. How do I get the value from the colorpicker to apply to a specific line segment?

edit…okay i have gotten it this far lol, but I can’t figure out how to get the line to pick up the new myPicker

<script type="text/javascript" src="jscolor.js"></script>

<script type="text/javascript">
var myPicker = new jscolor.color(document.getElementById('myField1'), {})
</script>

<script type="application/javascript" language="javascript">
window.onload = function(){
    var canvas = document.getElementById("myCanvas");
    var context = canvas.getContext("2d");
    var myStroke = "#ff0000";

    context.moveTo(100, 150);
    context.lineTo(450, 150);
    context.lineWidth = 10;
    context.strokeStyle = myStroke;
    context.stroke();
};
</script>
  • 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-26T21:51:42+00:00Added an answer on May 26, 2026 at 9:51 pm

    Haven’t tested it, but this should work:

    $('#yourColorpickerField').ColorPicker({
    onChange: function(hsb, hex, rgb, el) {
        var newColor = $(el).val(hex);
    
        var context = canvas.getContext('yourCanvasName');
        context.fillStyle = newColor;
        // here, you can draw your line again, or if you're already doing it on an interval, it should be fine for the next time you call it
    }
    });
    

    That assumes your lines are all the same color. I see that you want this to apply to only a “specific line segment,” in which case you’ll need to modify the above code. It’ll depend heavily upon what your existing code looks like, but basically, instead of setting context.fillStyle to the new color, you’ll want to store the new color value in another variable that you can read later when it comes time to draw that particular line segment (at which point you’ll set context.filleStyle to the color immediately before drawing the line).

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

Sidebar

Related Questions

I have external html5 canvas that you can paint on some lines using your
We have an HTML5 drawing app where users can draw lines using a pencil
I have a HTML5 canvas on which I have drawn several shapes. What I
I'm working with the HTML5 canvas element. Let's say I have 2 ImageData objects
I have made a game using HTML5 Canvas Element, Javascript for facebook. You can
I have made a snake game using javascript and HTML5 Canvas element. It can
I'm studying jquery and html5 canvas. All I want to do is a simple
i have some coordinates, which i want to draw on a HTML5 canvas step-by-step.
I'm making a game in html5 canvas. I'm using jquery so I can get
I have an HTML5 Canvas on my page along with two text input fields.

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.