[jQuery] question about identifying what should be updated in an an ajax post

[jQuery] question about identifying what should be updated in an an ajax post


I have only used jQuery for fairly simple things and am a little
stumped on how best to achieve the following. I have a list of items
(similar to the three items at the bottom) and I want a user to be
able to assign it as a favorite. I just copied the .post part from the
docs with the id in html comments but have two related questions:
1. what is the best way / preferred to get the id of value of the item
in the list (ie structured into the html - pretty sure an id can't be
just an integer)?
2. assuming I wanted to change the class back after a succesful update
(to say for example is_favorited), what would be a possible way?
$(function(){
$('.favorite').click(function(){
//alert('you want to save');
//alert(this);
$.post("test.php", {id: 'how do i get this'},
function(data){
alert("Data Loaded: " + data);
});
});
});
<span class='favorite'>something</span><br/><!-- 1 -->
<span class='favorite'>somethone</span><br/><!-- 2 -->
<span class='favorite'>something other</span><!-- 3 -->