If delegation is not your cup of tea, you can attach a click handler to a button before attaching a button. Do this by creating DOM elements and adding them:
var btn = $('<a />').text('Logout').attr({ "href": "javascript:void(0);", "id": "logout_button" }).click(function (e) { // do logout stuff e.preventDefault(); return false; }); $('#headerDiv').append(btn);
This has the added bonus of adding valid elements to the DOM.
source share