Q:

Change CSS of Dynamic buttons

I have the follow and is able to do the alert.  How can I change the class of the button selected? 
$('body').on("click", "button[name=likebtn]", function (){
    alert($(this).attr("value"));

    $(this).toggleClass('btn btn-mini likebtn');
// OR

    $(this).addClass('btn btn-mini likebtn').removeClass('btn btn-mini btn-primary likebtn');
});

The buttons are dynamically output:
$('#div').append("<button class='btn btn-mini btn-primary likebtn' name='likebtn' type='button' value='"+obj.value+"'>"+"LIKE"+"</button>");

I tried the following but failed:

A:

Maybe you should use removeClass() before addClass()
$(this).removeClass('btn-primary').addClass('btn btn-mini likebtn');

Because you add btn btn-mini likebtn by .addClass('btn btn-mini likebtn') and then you remove them by calling .removeClass('btn btn-mini btn-primary likebtn');
EDIT: If you want to remove btn-primary class only:
$('button[name=likebtn]').on("click", function (){
// ...
 $(this).removeClass('btn-primary');
});

