Reputation: 3898
I'm trying to do a simple thing. Simply attach a click listener to my page:
// Generated by CoffeeScript 1.6.3
$(document).ready(function() {
return $(document.body).on('click', '#container', function() {
return console.log("hello");
});
});
But I can't get the click events to register.
When I inspect the code in Firebug, I notice that it does recognize the event handler, but the function is not what I specified in the code:
From my kinda-intermediate javascript-knowing eyes, it looks like jQuery doesn't find that the element has a handler.
I have tried:
Reordering the loading of the scripts Attaching to different elements, different events Using event delegation Inspecting all over with firebug
I created a jsFiddle to recreate the issue: http://jsfiddle.net/wV5L3/
Any help would be great, bonus points for how I could have found the issue without consulting SO. Thanks.
Upvotes: 0
Views: 955
Reputation: 13014
It should be "body"
instead of document.body
$(document).ready(function(){
$("body").on('click', '#container', function(){
console.log("hello");
});
});
EDIT : When I tried your JSFiddle again, it seems to be working just fine. It is logging the output in console as intended. Am I missing something in question?
Upvotes: 1
Reputation: 6430
You are using too much returns. Use this -
$(document).ready(function() {
$(document.body).on('click', '#container', function() {
console.log("hello");
});
});
Upvotes: 0