I have a success function of jQuery defined as:
success: function(result) {
var htmlString = [result];
for (i = 0; i < htmlString.length; i++) {
$('#MyGrid tbody').append('<tr><td><a href="#">' + htmlString[i].name+ '</a></td><td><a href="#" class="remove">Remove</a></td></tr>');
}
},
And an event handler bound with delegate:
$('#MyGrid').delegate('a.remove', 'click', function() {
var name= ;$(this).closest('tr').find("td").eq(0).find('a').text();
var number = ; //here i need to access htmlString[i].number
alert(number);
}
How can I assign htmlString[i].number to the number variable?
there may be better ways but one way is to on the
successcallback assign theresultto some global scope variable and access it in the delegate callelse you can do it this way assign the
htmlString[i].numberto thereltagand in the delegate call