Report abuse

template


			

title ?>

This is some item. Delete it

result (html)


			

Some awesome item

This is some item. Delete it

Another awesome item

This is some item. Delete it

JavaScript


			
// wait until the document is loaded
document.observe("dom:loaded", function() {
  // a mouse click is observed on the "items" DIV
  $('items').observe('click', function(e) {
    var link = null
    // was the click on a link with a class "delete"?
    if ((link = e.findElement('a.delete') && confirm("Are you sure you want to delete this item?")) {
      // find the div and its ID, extract the number from it
      var div = link.up('div'), id = div.id.split('_').last()
      new Ajax.Request('/delete/path', {
        method: 'post', // don't use GET for destructive operations
        parameters: { id: id }, // will be available as $_POST['id']
        onSuccess: function(){
          // bye bye, record!
          div.remove()
        }
      })
    }
  })
})