Username: Posted November 29, 2011 Share Posted November 29, 2011 <script> $('#canvas').mousedown(function(e){ alert("test"); }); </script> <canvas class="canvas" id="canvas" width="500" height="300" style="border: solid 1px"></canvas> I'm almost positive there's nothing wrong This is killing meeeeee, please help Quote Link to comment https://forums.phpfreaks.com/topic/252020-why-wont-this-work/ Share on other sites More sharing options...
trq Posted November 29, 2011 Share Posted November 29, 2011 Did you forget something? $(document).ready(function() { $('#canvas').mousedown(function(e){ alert("test"); }); }); Quote Link to comment https://forums.phpfreaks.com/topic/252020-why-wont-this-work/#findComment-1292119 Share on other sites More sharing options...
Username: Posted November 29, 2011 Author Share Posted November 29, 2011 Did you forget something? $(document).ready(function() { $('#canvas').mousedown(function(e){ alert("test"); }); }); I sure did Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/252020-why-wont-this-work/#findComment-1292120 Share on other sites More sharing options...
Adam Posted November 29, 2011 Share Posted November 29, 2011 You don't need to wrap the code within a document ready event if it's within the body -- in-fact if it's within the body it makes more sense not to wrap it within the event. The problem is the position, you're trying to bind the event before you've actually defined the element. Move the JS just after and it would work. Quote Link to comment https://forums.phpfreaks.com/topic/252020-why-wont-this-work/#findComment-1292127 Share on other sites More sharing options...
Username: Posted November 29, 2011 Author Share Posted November 29, 2011 You don't need to wrap the code within a document ready event if it's within the body -- in-fact if it's within the body it makes more sense not to wrap it within the event. The problem is the position, you're trying to bind the event before you've actually defined the element. Move the JS just after and it would work. Well, it's gonna be a rather large code, so it has to be in a seperate file now anyway haha. http://pictureunrelated.com/screengrabbr/2.30.55-AM_2011-11-29.png It works alright I guess. It's really slow after about "Hello PHPFrea" Quote Link to comment https://forums.phpfreaks.com/topic/252020-why-wont-this-work/#findComment-1292128 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.