It’s been a while since I’ve done web programming and I’m trying to start again. However, I cannot seem to get JQuery to work.
In my javascript file I have this code:
$(document).ready(function() {
$('#canvas').mousedown(function(e){
alert("I am an alert box!");
});
});
However, nothing happens when I click the canvas.
I know everything is linked properly because at the top of my javascript file I have this:
function loader()
{
var canvas = $('#canvas')[0].getContext('2d');
canvas.fillStyle = "rgba(200, 0, 200, 0.5)";
canvas.fillRect(225, 105, 200, 200);
}
(In the HTML file I have <body onload="loader()">)
And that works fine and displays a pink box when I load the page.
Anyone know why this may be happening? Thanks.
Got it!
The problem was that I linked my javascript file before the jQuery file.
Basically, switched these two lines: