Skip to content

Conversation

@satyam22i
Copy link

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 satyam22i requested a review from a team as a code owner November 28, 2025 15:50
@satyam22i satyam22i requested review from wbamberg and removed request for a team November 28, 2025 15:50
@github-actions github-actions bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Nov 28, 2025
@wbamberg
Copy link
Collaborator

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.

@Josh-Cena
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Poor choice of canvas id

3 participants