Time for action – adding the behavior

Finally we can add the script that will make it all work. In the empty function at the bottom of the <body> element, add the following:

var messageList = document.getElementById("messageList"),
  messages = $("table", messageList),
  confirmDiv = $("<div></div>", {
    "class": "confirm",
    text: "Really delete?"
  }),
  remove = $("<button></button>", {
    id: "delete",
    text: "Yes"
  }).appendTo(confirmDiv),
  cancel = $("<a></a>", {
    href: "#",
    id: "cancel",
    text: "Cancel",
    title: "Cancel"
  }).appendTo(confirmDiv),

  deleteRow = function(e) {

    e.preventDefault();

    $(this).closest("tr").fadeTo(400, 0.5, function() {

      $(this).addClass("pre-delete");
      confirmDiv.clone().insertAfter(messages);
      messages.find("a").unbind();
    });
  };
 messages.find("a").click(deleteRow); ...

Get jQuery 1.4 Animation Techniques Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.