I'm appending HTML elements with clickevents via jQuery. 
The creation must be able to give these clickevents variables, I end up in 
NOT DEFINED ERRORS.
function foo( bar ){
  // do something with bar
}; 
var bar = "lolbert";
$("#parent").append("<td onclick='foo(" + bar + ")'> Whatever </td>");
Of course, the last line ends in the element:
<td onclick='foo( lolbert )'> Whatever </td>
And the clickevent will cause a "lolbert is not defined" error. It's clear why this happens and that it doesn't work this way.
However, whats the correct way to handover variables for events created by jQuerys .append() ?

'afteronclick='foo(' + bar + ')'>!