Passing two functions with .click()

Passing two functions with .click()

I want to understand why the code in my first example doesn't work as expected (only the anonymous function is called?), and why my other example runs fine. Is this problem specific to .click() or to callback functions in general?

        Here,  only the anonymous function is called?

  1. $(document).ready(function () {

  2.     $("button").click(renameButton, function () {
  3.         $("div").append("<p>Para</p>");
  4.     });
  5. });

  6. function renameButton() {
  7.     $("button").html("New Name");
  8. }

EDIT: Ok, so I added renameButton(); below $("div").append("<p>Para</p>"); in my first example, and now both functions are called. Why didn't .onclick() handle the call of that function as well as the anonymous one - I mean calling both functions when the button was clicked?

        This works fine:

  1. $(document).ready(function () {

  2.     $("button").click(renameButton);
  3. });

  4. function renameButton() {
  5.     $("button").html("New Name");
  6.     $("div").append("<p>Para</p>");
  7. }