content icon indicating copy to clipboard operation
content copied to clipboard

Change canvas id to myCanvas in Path2D examples (Fixes #42155)

Open satyam22i opened this issue 2 months ago • 2 comments

Description

This PR updates the <canvas> element ID used in the Path2D examples.
The previous examples used id="canvas", which can lead beginners to accidentally use a non-canvas element with the same ID, resulting in the common error:

getContext is not a function

The examples now consistently use id="myCanvas".

Motivation

Using a more specific and less generic ID helps prevent confusion for new developers.
It avoids accidental misuse of <div id="canvas"> and improves the clarity and reliability of the example code.

Additional details

  • Updated the HTML <canvas> ID in both examples.
  • Updated corresponding JavaScript getElementById() calls.

Related issues and pull requests

Fixes #42155

satyam22i avatar Nov 28 '25 15:11 satyam22i

There are hundreds of these... should we try to fix them all? There doesn't seem to be a whole lot of point in just fixing one, if we think this is a big enough problem to be worth fixing at all.

wbamberg avatar Nov 28 '25 18:11 wbamberg

Personally +1 that this is a problem. It's not immediately obvious where getContext comes from since we are not documenting the canvas element itself. Even just unhiding the HTML code goes a long way.

Josh-Cena avatar Nov 28 '25 20:11 Josh-Cena

There's 101 such cases: https://github.com/search?q=%22%3Ccanvas+id%3D%5C%22canvas%5C%22%22+org%3Amdn&type=code&ref=advsearch

groda avatar Dec 17 '25 23:12 groda