JQuery, toggling a class on dynamic content
===

I need to add a class to a <TR> within a block of generated content coming from JSON. I believe it's barking on the toggleClass because the HTML is actually not generated yet. I figure I probably need to use .on() or .live() in some fashion.

I am not receiving an error, it's just not adding the class. Again, because the table content is being built dynamically I believe.

Here's the relevant code.

    // The data variable is a block of JSON
    for(i=1; i < data.length; i++){
     foo += '<tr id="bar">test</tr>';

     // Here's where I am trying to add the class, but it is not working.
     $("#bar").toggleClass("newClass");

    }