I would try using JQuery to bind the button to an event after creating it.
function toggle() {
$("#tb" + item.CommonCable)
.clicked ? $('#MyElement')
.addClass('clickedButton');
$("#tb" + item.CommonCable)
.removeClass("clickedButton");
$('#MyElement')
.toggleClass('MyClass');
}
function DisplayButtons(cableData) {
var newContent = '';
$.each(cableData, function (i, item) {
newContent += createButtons("tb" + item.CommonCable,
null, "submit", item.CommonCable, toggle());
$("#Categories").append(newContent);
$("#tb" + item.CommonCable).click(function() { toggle() });
});
}
You might have to clear out $("#Categories") first if you do this more than once, and be careful you append the buttons in the right order, but this should work. Assuming I understood what you were after.