Jason
Jason

Reputation: 52523

jQuery Binding Woes

I have a function:

function foo() { console.log('i run!'); }

And a binding to a button:

$(function() { 
   $('#myButton').click(foo);
});

I am almost positive that the console should not show 'i run!' until the button is clicked. I have no other #myButtons on the page (I have forple checked this), and yet foo continues to run when another unrelated button is clicked. There are no other references to foo (again, forple checked).

What could be happening here? Am I binding wrong?

Upvotes: 0

Views: 124

Answers (1)

karim79
karim79

Reputation: 342635

You're not closing you're document ready block properly, it is missing a closing parenthesis (and optionally a semicolon), try:

$(function() { 
   $('#myButton').click(foo);
});

Upvotes: 4

Related Questions