ajax - jQuery selector -
i have following html:
<tr> <td> <img id='1' class='promote' src='/images/plus.png' /> <span>0</span> <img id='1' class='demote' src='/images/minus.png' /> </td> <td> <img id='2' class='promote' src='/images/plus.png' /> <span>0</span> <img id='2' class='demote' src='/images/minus.png' /> </td> ... </tr>
next, i'm using jquery ajax:
$('img.promote').click(function() { $.ajax({ url: '/promote/' + this.id, success: function(data) { $(???).text(data.rating); }, datatype: 'json' }); }); $('img.demote').click(function() { $.ajax({ url: '/demote/' + this.id, success: function(data) { $(???).text(data.rating); }, datatype: 'json' }); });
so, combination of jquery selectors should use instead of "???" change text between span tags? or i'm doing wrong @ all? thank you.
you need cache span in click handler
$('img.promote').click(function() { var $span = $(this).siblings('span'); $.ajax({ url: '/promote/' + this.id, success: function(data) { $span.text(data.rating); }, datatype: 'json' }); });
Comments
Post a Comment