jQuery - getting the id of the item selected

Posted by John Leonard on Stack Overflow See other posts from Stack Overflow or by John Leonard
Published on 2010-05-01T11:45:55Z Indexed on 2010/05/01 11:47 UTC
Read the original article Hit count: 215

Filed under:
|

I have a basic jQuery selector question.

Let's say I'm parsing JSON and generating a row of data for each item in my result set. On each item row, I want an action button. What is the best practice to script that button so its click action can reference the data specific to that row?

Starting with the block below, how do I generate a 'Click Me' button that when clicked will alert with its json data?

   $.getJSON(url,params,function(json){
    if(json.items){
        $.each(json.items, function(i, n){
            var item = json.items[i];

© Stack Overflow or respective owner

Related posts about JSON

Related posts about jQuery