How to use getContext() in jQuery

How to use getContext() in jQuery

I'm trying to use&nbsp;getContext('2d');&nbsp;in jQuery. I have seen&nbsp;<a href="https://stackoverflow.com/questions/2925130/jquery-equivalent-of-getting-the-context-of-a-canvas" target="_blank">this question</a>, but it doesn't seem to work. It could possibly be from updates, since the question was asked near 9 years ago. I am adding&nbsp;&lt;script src='<a href="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'&gt;&lt;/script&gt;" target="_blank">https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'&gt;&lt;/script&gt;</a>&nbsp;in the head, but using a different&nbsp;&lt;script&gt;&nbsp;tag. Here is all my code:

I'm trying to use getContext('2d'); in jQuery. I have seen this question, but it doesn't seem to work. It could possibly be from updates, since the question was asked near 9 years ago. I am adding <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script> in the head, but using a different <script> tag. Here is all my code:

var c = $('.canvas');
var ctx = $(c)[0].getContext('2d');

window.onload = function() { $c.width(500); $c.height(250); $c.css({'background-color': '#e2e2e2', 'margin': '0 auto', 'display': 'block'}); } <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <canvas id='canvas'>You're browser does not support the requirements to play this game. Update your browser or use a different browser</canvas>


I'm using Google and checking the console through F12, and it says -

Uncaught TypeError: Cannot read property 'getContext' of undefined

Any help is appreciated! Thanks!

jquery

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Dedicated Jquery Developer

Are You Looking To Hire a jQuery Programmer? **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, a leading jQuery application development company, can help you build interactive front-end solutions to leapfrog the digital...

Querying DOM in jQuery | jQuery Tutorial for Beginners

This video on Querying DOM in jQuery will help you understand the DOM manipulation methods with hands-on.

jQuery Live - 3 | jQuery Plugin Tutorial For Beginners | jQuery Tutorial | jQuery Training

This video on jQuery will help you understand how to use the jQuery Plugins with practical examples.

Forms and Events in jQuery | jQuery Tutorial | jQuery Training

This video on Forms and Events in jQuery will help you understand what are Forms and how you can create events on them in jQuery.

jQuery Live - 2 | jQuery Utilities Tutorial | jQuery Tutorial

This video onjQuery Utilities Tutorial will help you understand the basics of jQuery Utilities. You will also be able to create your own program using jQuery by the end of this video.