I am remaking a page on the admin section of a website I administer so that it uses jQuery and AJAX. On one of the pages I have a list of items. Next to each item there is a link which is something like this:
<a href="delete.php?id=48" class="del_link">delete</a>
If I give these links a class I can easily apply a jQuery function to all of them but they would all call the same function in the same way. My question is: what is the best way for the function to get the item's id without including JavaScript inline with the html?
Update: Thanks for the pointers, everyone. I've ended up using this:
$(".del_link").click(function(){
var del_link = $(this).attr('href');
$("#results").load(del_link, function (){
$("#results").show().delay().fadeTo(2000, 0);
})
})
The php file that the ajax calls responds in different ways if it's been requested by ajax or normally - if it's ajax it outputs a response (e.g. "Item was deleted successfully") which can be displayed in the #results div. If someone has javascript disabled the client will be directed to the same php page but it will redirect them once the item is removed.