You could try using a hidden field to hold the id. Then you could look for that field. $(document).ready(function() { $('.favorite').click(function(){ var tid=$('.hiddenfield').text(); alert(tid); }); }); <p><a href="#" class="favorite">some link<span class="hiddenfield">109</span></a></p>
not sure about prefered method, but that might work On Jul 11, 5:24 pm, jt <j...@arclocal.com> wrote: > 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 -->